What type of network programming is needed in an online multiplayer iPhone game?

I ask this question as a small part of my series of questions on game programming.

Submit this question as the main one.

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

Suppose his table is a casino.

In the main question, ChrisF told me about his Client-Server architecture for the multi-player iphone game.

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

What will be the responsibilities and actions performed by the client and server.

You can provide me with a link, tutorials or answers to questions, something will be of great help to me and will be very noticeable.

thanks

+4
source share
3 answers

You need to write a socket application running on the server. When you have access to a wifi access point or / 3G edge, you can send data to it from the iphone application. Then this server can process incoming data and send the corresponding response to related people.

To program server sockets, check out this guide - http://beej.us/guide/bgnet/ .

For programming iphone-specific sockets, take a look at the samples that come with the Iphone SDK. This link also contains some basic information.

+4
source

Simple online multiplayer game

Given that the iPhone is not always connected to the Internet, you may need a server to store state. Alternatively, you can always indicate that if one person loses touch, the game ends.

Customer to customer would be the obvious choice for the latter. Both clients have a port that they listen on and send other commands based on the state of the board. As with almost all online games, the obvious choice would be to use UDP, as it is fast and compact.

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

This second approach, using the JSON / SOAP route, will be a lot easier for you to start by assuming the iPhone has a decent JSON or SOAP library, which is unlikely. I have no idea about UDP in Objective-C, but in C it requires a certain level of knowledge that will not make you play fast.

+2
source

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

  • The server can only serve as a gateway between players for connecting to each other: its two use is, firstly, a list of running games, and secondly, a list of players IP addresses, so that each client will read IP addresses and connect to him. This will require less bandwidth and processing power for the web server and more for the client who will host the game. In this configuration, one of the clients will act as a server and will send data to others. If your game has only one of the players playing at a time, and not a lot of players, this is what you should use, since you are paying for the power of the server.

  • The server can also store all the states of the games: your game may require much more processing power and / or bandwidth.

In any case, most of the time you will need only one machine (which can change during the game, as in the first case) to perform processing, and the rest will receive only the calculated data.

To program a network game, you need knowledge of sockets (deep knowledge in the first case, because you have to deal with NAT problems, routers block the path between clients). The Beej Guide to Network Programming is the number one guide in this section, although it does not focus on games.

If the WWW server does not require too much processing, you can deal with it using server scripting languages ​​such as PHP along with MySQL, but you will most likely use your own server programmed in C ++ (or C ) If you use C ++, you can use an existing library such as RakNet .

The client will obviously be programmed in Objective-C, as on the iPhone. I believe that there is a good network infrastructure that studies the number of online games, so you may not want to use a network library of external servers.

It may be too much for what you want to do, but you can also use the famous Torque Engine .

+2
source

Source: https://habr.com/ru/post/1314162/


All Articles