Android / libGDX: High ping times in simple TCP connection

Using libGDX’s network library I have to android phones connected via tcp sockets over a local LAN. Surprisingly this results in a ping of about 300ms. This seems crazy high for a LAN connection.

tcpNoDelay is on (on both ends), and the socket hints are set to low latency preferred. Sockets are polled in the main loop and handled immediately if a message comes in.

The same test between one android phone and a desktop version gives a ping of about 160ms, and running two instances locally on a desktop gives a ping of somewhere between 16ms and 33ms (a frame’s worth of lag at either end I’d say).

So the android stack seems to add about 100-150ms of latency at both ends before it even hits the network. This seems crazy high to me - does anyone know if this is normal, or if there’s anything that I can do to bring it down?

Hmm, disappointingly WIFI_MODE_FULL_HIGH_PERF doesn’t get me a lower ping. :frowning:

http://developer.android.com/reference/android/net/wifi/WifiManager.html#WIFI_MODE_FULL_HIGH_PERF

Seems high for LAN but then again I wouldn’t expect smartphones/tablets to be capable of any kind of real time networking without WiFi and even then expect an average 500ms.

Do you really need low latency on smartphones/tablets?

This is a local lan via wifi - I’m not sure why you’d expect such bad ping times? Mobile phones are pretty much full computers now, just with a locked down OS. With a wifi laptop on the same lan I can ping google and get ~20ms response times, and that includes going over the internet to google’s server and back.

Poking around in the options there’s ‘power savings’ settings which seem to affect the wifi, but with everything off the ping time remains unchanged.

They really are quite alike full computers but at the same time they really aren’t. And they come in a lot of different shapes and sizes. To be honest this looks like tcp nodelay isn’t really working like it’s supposed to or it’s incapable because of some hidden limits. I don’t know.

If you don’t mind me asking, why would you need such real-time networking anyway?

All of that nonsense being said however, I work for a company that makes its living on real-time information carried out by smartphones (HTC Android running a java application to be exact.). I don’t know the full networking details but we can get some pretty decent pings (~100ms or less as far as I can tell*) quite constantly on 3G networks (lag spikes occur and even disconnections occur from time to time). I’m pretty sure the companies packets are throttled with higher priority than most, though. And the average time between messages sent is around 10 sec (mostly in short bursts).

*These numbers aren’t measured accurately. The ping just “looks instant”, if that makes sense? E.g. Press send, get immediate response. Whatever ping suffices that criteria.

For a real-time multiplayer game, of course.

Obviously I need client prediction and latency hiding and all that jazz, but when my baseline, best possible conditions ping turns up at 300ms then that’s really worrying.

I may knock up a udp test and see how the latency compares (annoyingly libGDX doesn’t support UDP from what I can tell. :frowning: ).