Online real time multiplayer game for iOS 5/6

I know there are already some posts about this topic, but I cannot find the answer I need and I do not know where to start.

I would like to create an online multiplayer game for the iPhone where players can play together against each other over the Internet. For example a 2 player racing game where once the 2players are matched and connected they can both control their cars in real time against each other. E.g like mario cart.

I know that the game kit does thus but only over Bluetooth or over the same wifi network. I would like this to be over the Internet (wifi only) where players can play against each other around the world.

I know there are already some frameworks to do this. But they are costly and depend on the number of connections. Is there a cheap or dare I say, free way of doing this? Like have game kit do the matching and then the connections and sending data is done some other way? Like having the iPhones host the games? Rather than having a dedicated server. I do not have the budget nor the knowledge and experience to create a dedicated server.

The matching is simple. There are 30 levels and any 2 players wanting to play the same level are matched.

Any links or book recommendations are welcome. I have very limited networking knowledge and do not know where to start.

I can read and learn the techniques even if they are technical but I will need the right resouces to allow me to make a start

Thanks in advance.

Answers


You actually can do exactly what you are looking for using the Game Kit API's. Basically, you create a match using the GKMatchMakerViewController. To make the match you use the GKMatchMakerViewController to start looking for other players, once it finds other players it notifies the GKMatchMakerViewControllerDelegate that a match has been found and will pass the GKMatch object. Then you need to have an object which implements the GKMatchDelegate protocol to handle the actual data. You set your delegate object to be the delegate of the GKMatch you are passed, and then use methods from the GKMatchDelegate protocol such as – match:didReceiveData:fromPlayer: and methods from GKMatch to send data.

Heres some example code to help with that explanation. This is just the bare essentials, you of course need to implement your gameplay stuff, and some error handling.

Also, you can find the documentation you need at these four links

GKMatchMakerViewController GKMatchMakerViewControllerDelegate GKMatch GKMatchDelegate

- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID{
    if(matchStarted){
        Packet *msg = (Packet *)[data bytes];
       //do whatever you want with the data received from other people
    }
}

-(void)sendPosition{
    //call this to update the other players devices (should be self explanatory)
    NSError *error;
    Packet msg;
    //Here the msg object is actually a typedefed struct name Packet. I use this to send and receive data
    NSData *packet = [NSData dataWithBytes:&msg length:sizeof(msg)];
    [myMatch sendDataToAllPlayers: packet withDataMode: GKMatchSendDataUnreliable error:&error];
    if (error != nil)
    {
        // handle the error
    }
}

#pragma mark MatchSetup

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match{
    [self dismissModalViewControllerAnimated:YES];
    self.myMatch = match; // Use a retaining property to retain the match.
    self.myMatch.delegate = self;
    if (!matchStarted)
    {
        // Insert application-specific code to begin the match.
    }
}

You should check out real-time peer-to-peer networking service PubNub as it sounds like a perfect match for your project.

I found PubNub very easy to implement even with my modest programming knowledge. Integrating different platforms was also easy as there are SDK's for most common languages. I had a PHP based web page that served as a scoreboard for my iOS based app.


What you're looking for is a GameKit "hosted match" wrapper, which possibly does exist. The caveat is that Apple doesn't host these types of matches, your own server does. So, you'd need a webhost, and those aren't usually free. Amazon's AWS is free for a micro-instance, but depending on scale you would probably top out with enough synchronous play.

I'm more interested in learning about potential GameKit wrappers now that you've brought it up. Can you comment on what you've found, you mentioned that they're expensive and have limits on connections.

PS - Apple's limit is up to 16 players


Need Your Help

How to extend chrome memory profiler to show it in different UI?

google-chrome google-chrome-extension google-chrome-devtools google-chrome-app

I want to extend chrome memory profiler for my website. Basically I want to use chrome dev tools to take snapshot for my website which will have different data like memory used , time to load , CPU

Google Script Calendar Events Time Zone Is Off 7 hrs

javascript calendar timezone

I am new to google scripts (any programming for that matter and have pieced together a few scripts I've found on the internet, then changed a few things I could figure out to make it work for my pu...