views:

107

answers:

3

Hi all ,

I am asking this question as a small part of my question series regarding game programming .

Refer this question as the main one .

Now suppose I want to develop a game on iphone - a simple online multiplayer board game.

Suppose its a casino table.

In the main question ChrisF has tell me of sort of Client - Server architecture for iphone online multiplayer game.

I want to know what sort network programming I have to do for this type of application .

What will be the responsibilities and activities carried out by client and server .

You can provide me link, tutorials or to the point answers , anything will be great help for me and will be really appreciable .

thanks

+4  A: 

You'll want to write a socket application running on a server. When you have access to a wifi access point or edge/3g you can send data to it from your iphone application. This server can then handle the incoming data and send an appropriate reply to the people connected.

For server socket programming, take a look at this guide - http://beej.us/guide/bgnet/.

For iphone specific socket programming, take a look at the samples supplied with the Iphone SDK. This link also has some basic information.

Chaoz
Hey chaoz thanks for your answer but I want to know the client side part also i.e. iPhone . What sort of things are applicable for iPhone network programming ?
hib
is it in c ? @ Chaoz
hib
+1 for beej's guide
fmark
+1 because nothing beats Beej's guide
Fififox
+2  A: 

A simple online multiplayer board game

Given that the iPhone isn't always connected to the internet, you might need a server to store state. Alternatively you could always stipulate that if one person loses their connection the game finishes.

Client to client would be the obvious choice for the latter. Both clients have a port they listen to, and send the other commands based on the board state. Like almost all online games the obvious choice would be to use UDP as it's fast and compact.

For the server architecture you will of course need some kind of server listening for commands and a game number. It would store your state in a datastore on the server, a mySQL database for example. UDP or even SOAP or JSON over HTTP would be the two obvious choices for this.

This second approach using JSON/SOAP route would be a lot easier for you to get started with, assuming the iPhone has a decent JSON or SOAP library which is not likely. I have no idea about UDP in Objective C, however in C it requires a certain level of knowledge which won't get you something to play with quickly.

Chris S
Thanks @Chris S I got lot of things from your answer
hib
You should consider the fact that you might not get the performance you need when using HTTP; If you need a fast responce but high reliability go with TCP sockets.
Chaoz
SQLite is a lightweight alternative to MySQL.
zooropa
+2  A: 

As you already said, you will need a server, but you can have two kinds of design:

  • The server can serve only as a gateway between the players to connect one to each other: it's two uses are, first, to list the running games, and second, to list the IP addresses of the players so that each client will read the IP addresses and connect to them. This will require less bandwidth and processing power for the web server and more for the client which will host the game. In this configuration, one of the clients will act as a server and will send data to the others. If your game has only one of the players playing at a time, and not a huge lot a players, this is what you should use as what you pay is the server's power.

  • The server can also store all games' states: it might require far more processing power and/or bandwidth depending on your game.

Anyway, most of the time you will want only one machine (which can change during the game as in the first case) to do the processing and the others will only receive the computed data.

To program a networked game, you will need knowledge of sockets (deep knowledge in the first case because you will have to deal with NAT issues, routers blocking the way between clients). The guide to that is Beej's Guide to Network Programming, the number one ressource on this topic, although it doesn't focus on games.

If not too much processing is needed on the WWW server, you could deal with it with server scripting languages like PHP along with MySQL, but you're most likely to use your own server programmed in C++ (or in C). If you use C++, you might want to use an already existing library such as RakNet.

The client will obviously be programmed in Objective-C as it's on the iPhone. I believe there is a good networking framework looking at the number of online games, so you might as well not want to use an external server networking library.

It might be a bit too much for what you want to do, but you could also use the well known Torque Engine.

Fififox