iPhone OS 3.1 & GameKit Pt. 4: WiFi

I’ve finally found the time to continue working on my WiFi backend (it can be used as a drop-in replacement for the iPhone GameKit, shares the same interface and works almost identically). While not everything is working yet, I was able to run some simple preliminary latency and bandwidth tests.

Apparently, the latency of a single ping/pong packet is around 100ms-150ms. This comes at no surprise, it’s what I’ve posted before. However, when I start to send (unreliable) data at a constant rate, like 3-10KiB/s, it will simply use UDP to do that, the latency drops down by about 90%. Yes, I can achieve latencies of around 15ms. However, they are a little more unstable than the Bluetooth latencies. I’m sometimes still seeing up to 100ms in between, but the average and most of the packets are around 15-20ms.
I wonder where that comes from. An educated, but fully out-of-the-air, guess would be that maybe the antenna is powering down when the device doesn’t send anything for a few milliseconds, to conserve power, and it has to power up for a few milliseconds when something is being sent. However, this is only my own guess and I don’t expect it to be even close to reality. If you have more information on that, please let me know. Maybe it sheds some light on how to control the latency issues.

6 thoughts on “iPhone OS 3.1 & GameKit Pt. 4: WiFi

  1. All your posts on the gamekit have been an interesting read.Thank you. As an indie developer I'm interested in if you are planning to release the code for your wifi gamekit replacement?

  2. Hi Hactar,

    thanks for the feedback. I can't really say that since the code will be used in production (it's based on Limbic code but I'm also using it for a research project at my lab).

    However, it's not rocket science, mostly engineering. I essentially took the GameKit interface, wrote a wrapper around it (using a ObjC @protocol) and then wrote two implementations: one using GameKit, and another one using plain old C sockets.

  3. Thanks for the quick answer.

    Well essentially, while not rocket science it still is work and no-one wants to reinvent the wheel ;). But I understand the difficulties of releasing production code, though I'm pretty sure it would spark some interest.

    As I'm just starting out in analyzing GameKit while you have experience with it, have you managed to figure out what apple wants us to do with GKPeerPickerConnectionTypeOnline? I'm currently programming a little game which I hope to initially release with p2p support, but would like to add full online (internet) support later and I'm not sure how (or if) that can be done with GameKit. The option is there, but the documentation for this is lacking…

    This is where the WiFi replacement for GameKit would come in handy I guess, as that is socket based…

  4. I'm not using the PeerPicker, and I strongly recommend not using it. It is using the GKSessionTypePeer mode, which may take a long time to find peers (opposed to the GKSessionTypeServer/Client, as I've written in my posts).

    While the peerpicker "offers" online play via the GKPeerPickerConnectionType, it is not implemented at all. In the documentation, all they say about the online mode is here: http://developer.apple.com/iPhone/library/documentation/NetworkingInternet/Conceptual/GameKit_Guide/FindingPeerswithPeerPicker/FindingPeerswithPeerPicker.html
    So once you select the online mode, you essentially have to do everything yourself.

    My WiFi implementation isn't designed for online mode, too. It's designed for local play with more than 3 people, and to be more reliable than the bluetooth implementation.

  5. Right. I noticed though, that if you do not use one of them (ie. no Wifi during Gamekit'ing), it will work without problem… just don't use both at the same time.

Leave a Reply

Your email address will not be published. Required fields are marked *