Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am currently programming an iPhone game and I would like to create an online multiplayer mode. In the future, this app will be port to Android devices, so I was wondering how to create the game-server?

First at all, which language should I choose? How to make a server able to communicate both with programs written in objective-c and Java?

Then, how to effectively do it? Is it good if I open a socket by client (there'll be 2)? What kind of information should I send to the server? to the clients?

share|improve this question
add comment

3 Answers

I don't mean to start a holy war here, but most of the internet services (flickr, twitter, facebook and such) have been dropping SOAP in favor of RESTful webservices and JSON as the serialized format. Although essentially the same, REST services rely on the url and http method to define what should be done, for example

GET /articles - list all articles
POST /articles - add a new article
PUT /articles/123 - update article 123 with new data

JSON - described in json.org - is also simpler than XML, and altough maybe irrelevant, will save you a few bytes per request. Following the previous example, here's how an article would be described in JSON notation:

{ 
 "id": 123,
 "author": "Cyril",
 "content": "Hello, this is an article",
 "tags": [ "gamedev", "webservices", "multiplayer" ] 
}

For the IOS there's this nice article http://petermcintyre.wordpress.com/2010/11/04/consume-json-rest-in-ios/ which mentions http://code.google.com/p/json-framework/ for parsing and generating the data.

Being turn-based, you can rely on http sessions on the server to maintain state, so there's no need to keep a persistent socket connection to the server. Any server-side language supports this (php, python, java, etc).

This architecture allows you to scale horizontally (adding more servers) in a transparent way.

share|improve this answer
add comment

Since your game is going to be turn based, real-time updates are not super important. The easiest way to do this is to use an already built server, I would go with a web server. Any platform worth porting your game to should facilitate accessing web services located on a web server.

In order to provide updates in near real-time, I recommend you look into long polling. The code at that link, provides the most basic implementation of long polling from the server side. But the bottom line is that once a request is made to a resource, the server executes a blocking call until the data requested becomes available. Then you repeat the process again, and again.

In terms of what data should you send back, always treat the client as hostile. The client should send whatever its "turn-state" is, the server validates it, and then if everything checks out, it sends the new "game-state" back to all connected clients.

--

SOAP web services is probably the best place to start (link), they are easy to get started, and most web frameworks provide a method for exposing them. You might also want to look into RESTful services, but they typically leave a bit more of the serialization process up to the consumer.

For consuming SOAP web services on Android, I'd look here.

share|improve this answer
    
Hi and thanks for your response. But I don't understand yet how to send data to my webservice ? how to serialize the user input (here a move in my 8*8 board eg: player 1 from [0,0] to [1,1]) and then how to serialize the game state ? –  Cyril Feb 12 '11 at 18:39
    
Check the two links I added. They should get you started with SOAP web services, which is probably the most simple way to get started. –  Nate Feb 12 '11 at 18:54
    
For Android and iOS you shouldn't need to use long polling. Apple Push Notifications or Google Cloud Messaging will let you push data from the server to your devices. –  Matthew Sep 14 '12 at 5:35
add comment

I think using SOAP or even HTTP is overkill. Just define your own protocol over vanilla TCP-connections. For example, interpret each line of text sent as a command. Define what commands/responses the client and the server is allowed to send.

FICS works that way and it has been serving thousands of chess players for many years. IRC works that way too (see RFC 1459).

share|improve this answer
    
HTTP offers several advantages, though: it can use proxies, it's almost never firewalled, it offers near transparent encryption using HTTPS, has several authentication methods... –  Sam Hocevar Apr 14 '11 at 15:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.