To evaluate TCP compared to UDP on iPhone, I wrote a small echo server on my computer and used the AsyncUdpSocket library on the iPhone, but the delays come out surprisingly large, and I'm wondering if something is wrong with my implementation somehow .
In my setup there is a Wi-Fi router (Apple Airport) which has an external static IP address. The port used by the echo server is redirected to my development computer.
I used two different settings:
- iPhone → Wi-Fi → Wifi Router → Wi-Fi → Computer
- iPhone → 3G → Wifi Router → Wi-Fi → Computer
The packet size was about 10 bytes.
In the first case, the circuit ranged from 9 ms to 600 ms. Basically, I would see a median of about 300 ms, but some runs will only have 30 ms.
The second case ... The best case is 2000 ms, moving up to 5000 ms.
The implementation will send a UDP packet, wait for it to return, then send the next one.
I initially thought that something was wrong with the implementation, but running it from the simulator gives a constant delay of only 7 ms.
Are my numbers correct or is something strange happening?
Nuoji source
share