Domanda

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:

  1. iPhone -> Wifi -> Wifi Router -> Wifi -> Computer
  2. 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?

È stato utile?

Soluzione

I saw this link on iphone Wifi latency and I decided to try pumping UDP packets faster.

I started lowering my delay between receiving a ping and sending a new ping until I reached 50 ms.

At 50 ms, the UDP ping (roundtrip) was down to around 80 ms using 3G (remember, this was originally around 2000 ms)!

TCP also improved, but not as much as UDP. I would get 100-200 ms, again on 3G.

My conclusion is that iPhone powers down the antennae, which severely affects UDP. TCP is better, because the phone knows of the open connection and is faster to power up.

Incidentally during packet loss, TCP would reach pings of 1000-2000 ms. This coincides with own observations that TCP connections would occasionally suffer large delays on the iPhone.

Altri suggerimenti

I send a udp packet of 1 byte every 30th of second and the latency desapeared. This way the antenna never sleep.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top