I made a simple pong game from a tutorial (icode blog)and would like to play againt another player over my wifi network. How do I add that feature to the game?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.