Game Server data transmission

Started by
8 comments, last by SimonForsman 13 years, 9 months ago
Hello!

I am not a game maker, but I am making a Gaming server, and I was wondering how game data is sent from the server to the client and vis-versa.

I am trying to make the server universal for many languages: Flash, C++, C, C#, VB.NET, python, etc.

What is a common way to send/receive the data, and is there a better way to do it with a particular language? For example flash uses XMLSockets (I don't know what the others use).

The server will be written in on of two languages, depending on my needs, and that would either be python, or php.

Thanks for your help!
Advertisement
I am not 100% sure what you are asking but I think i know. Data is data, if its an array of bits from python its an array of bits for C++ as well. You must then design a protocol so that data can be read and interpreted by both the Client and Server.

This might be for example:

[1 Byte denoting what this data is all about]
[2 Bytes denoting how long this data is]
[N Bytes "The data"].

"The data" would depend entirely on what you need to send and the server/client would know how to parse that based on your first byte which says what its all about.

If however you want to know how to actually send that data, you use 'Sockets' and you will want to probably use 'TCP' Sockets. They are easy to access in C++,C#,VB and python (unsure about Flash) and you will just need to reed up on them in each languages documentation.

To Stress: It is impossible to design a protocol that depends on the programming language used to read it (probably :) ).
Also: For your second quesion 'whats the best way to do it', there are better ways to do it in the DOT NET enviroment and C++ called IOCP (Input Output Completion Prots) I do not understand them entirely but C# encapsulates them in a really easy to use way and they are used through ASynchronus methods. (GOOGLE it for best results :) )
Lets say you have your game, and you want ObjectA to move from PointA (0,0)(x,y) to PointB (100,300)(x,y).

What might you send to the server, and what actions might the server take to perform that task?
If you ( the client, who connected to the server ) can control ObjectA, then you would send a packet telling the server that ObjectA moved to [100,300]( aka. pointB). Then the server would notify all players who need to know about this ( for example, everyone in the same room, or just all clients, except the one who sent the info).
All the clients would initially know that ObjectA is at pointA, they would be notified when they join the game or when the object moved there.
Ok, so ill show you what i would do:

We need to do two things: Define a protocol and then Decide what the server should do:

FIRST THE PROTOCOL:

Okay, so our first Byte that we send tells the server our message.
Second and Third are a 16bit integer a 'short' telling the length of the message.
Finally there are N many bytes, N is defined by bytes [2 & 3].

We will say that one command is the command MOVE and this represent the number 001.

So the data we need to send is as follows:
[MOVE COMMAND]
[LENGTH = 8 ]
[DATA [INTEGER / X][INTEGER / Y] ]

Then once this is sent by the client, the server knows that the client want to move from its current position to X,Y. It knows this because it can parse out the data from the message it has recieved. NOTE: I have assumed using binary, but if you would prefer to use Strings, this is also possible using the same technique.

The server would then store this infomation and send it to all the other clients who care about this. So, if it was a game , all the people on that clients level should be told. {For simplicity it may be easier just to send it to everyone}.

SO a little Timeline of this happening might be as follows:

...
PLAYERA sends message [001,8,100,300] //MOVE to (100,300)
...

SERVER recieves message from PLAYERA
SERVER stores data
SERVER sends message to all PLAYERS who can see PLAYERA
...

Quote:Original post by anttooking
...
SERVER recieves message from PLAYERA
SERVER stores data
SERVER sends message to all PLAYERS who can see PLAYERA
...


What do you mean "SERVER stores the data"? how does it store the data? In memory, in a database...???
You probably need to step back a little bit and figure out exactly what kind of games your server will be good for.

There are at least three kinds of servers used for games:

1) Matchmaking/lobby servers. These allow a user to "host" a game, and other users to find "hosted" games to join.
2) Scores/statistics servers. These implement things like online leaderboards, character progression, and other persistent data storage.
3) Game mechanics servers. These receive requests from clients about changing game state, validate the requests against game rules, and distribute results to other clients.

Some games clearly delineate these different responsibilities. Other games bundle them all together. Especially MMO games will cluster up one or more instances of each, and then have the client connect to that cluster.

The important parts of the servers vary by their role.

For a matchmaking server, being able to quickly find matches that result in fair and fun games for everyone (skill, goals, play style, etc) is important.

For a statistics server, the ability to screen out cheaters who attempt to upload fake statistics is important.

For a game mechanics server, there really are two kinds: Turn-based, where each player provides instructions for a turn, and the game then advances, and real-time-based, where the state of the game evolves at a fixed pace no matter what. Turn-based games often have laxer performance requirements than real-time based games.

Most real-time based games end up pulling out all the stops in optimizing the bandwidth used by the communication protocol, which means that a bunch of game-specific knowledge is encoded in the protocol. Thus, it's hard to build a generic server for real-time-based games that has high enough performance to be competetive. Typically, you'll want to support 32 simultaneous online users, using no more than 8 kilobytes per second per user of bandwidth, and sending at least 10 updates a second to each user. (High-end games send 30 times a second and support up to 128 simultaneous players)

MMOs are often a hybrid of turn-based and real-time. They may delegate physics simulation to the clients, and only send updates that affect game state (hit points, equipment change, etc) between clients immediately. For movement, they may send the desired position of each entity "near" the player more often than entities "far" from the player. This filtering has to be done on a per-player basis from the server side.

Good luck on your game server project, and please let us know how it goes!
enum Bool { True, False, FileNotFound };
Quote:Original post by GMServer
Quote:Original post by anttooking
...
SERVER recieves message from PLAYERA
SERVER stores data
SERVER sends message to all PLAYERS who can see PLAYERA
...


What do you mean "SERVER stores the data"? how does it store the data? In memory, in a database...???


That would be decided by you, you could store it in the database for every single movement or you could just save to memory and only save to a database say every 60 seconds. That is the kind of thing that you will have to decide as both have Pro's and Con's
Quote:Original post by anttooking
Quote:Original post by GMServer
Quote:Original post by anttooking
...
SERVER recieves message from PLAYERA
SERVER stores data
SERVER sends message to all PLAYERS who can see PLAYERA
...


What do you mean "SERVER stores the data"? how does it store the data? In memory, in a database...???


That would be decided by you, you could store it in the database for every single movement or you could just save to memory and only save to a database say every 60 seconds. That is the kind of thing that you will have to decide as both have Pro's and Con's


I'd recommend against using a database unless the game is persistent, for a FPS for example the only thing you might want to use a database for is statistics/rankings/ladders/etc and then its enough to store those at the end of the rounds or maps. (player positions etc are best stored in ram).

As has been said before though, its very hard to make a good generic game server since different games have very different needs.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

This topic is closed to new replies.

Advertisement