开发者

How to connect over wifi for game play?

I made a simple pong game from a tutorial (icode blog)and would like to play againt another player ove开发者_开发问答r my wifi network. How do I add that feature to the game?


There are two ways to go about this. The first, and easiest, is to use Game Kit's peer-to-peer networking to connect two devices. As of iPhone OS 3.1, Game Kit works over WiFi as well as Bluetooth. I show how to do this in the Networking session of my iPhone class on iTunes U. This sample application I wrote for the class demonstrates the use of Game Kit to communicate between two applications.

While Game Kit is the simplest way to go, it only works for communication between two devices running iPhone OS 3.1+. For more generic WiFi networking, I'd recommend looking to Bonjour discovery. Again, I show an example for that in the above-linked class, and use code assembled by Bill Dudney in his "Bonjour Network Server for iPhone" article. The neat thing about this approach is that you can also communicate with desktop applications, like with the Mac client that I created for the class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜