In order to evaluate TCP versus UDP on the iPhone, I wrote a small echo server on my computer and used the AsyncUdpSocket library on the iPhone, but latencies are coming out surprisingly large and I wonder if there is something wrong with my implementation somehow.
My setup has a wifi-router (Apple Airport) which has an external static IP. The port used by the echo server is forwarded to my development computer.
I used two different setups:
- iPhone -> Wifi -> Wifi Router -> Wifi -> Computer
- iPhone -> 3G -> Wifi Router -> Wifi -> Computer
Packet size was around 10 bytes.
In the first case, roundtrip varied from 9 ms to 600 ms. Mostly I would see a median of around 300 ms, but some runs would have only 30 ms.
Second case... Best case 2000 ms, moving up to 5000 ms.
Implementation would send an UDP packet, wait until it gets back, then send the next.
I initially believed something was wrong with the implementation, but running it from the simulator give a consistent latency of only 7 ms.
Are my numbers right or is something weird going on?