Skip to main content
GameDev.net gamedev.net
🔒 Locked

Designing Game Network Protocol

Started by bgilb Feb 21, 2005 at 5:24 AM 4 replies 1.6k views
Original Post
bgilb
bgilb
I was just about to jump into some random programming to try and get the job done, but I thought I would come in here to ask for input :D Im trying to design the protocol for a multiplayer game, server side and client side Basically what i need is some advice these areas: How does each client handle other clients How does each client hanlde sending out to each client that its connecting How does each client handle clients that didn't send out that message but do exist.. How do clients handle sending and recieving player updates ( position x , y etc ) + any other things you think i might have trouble with Should each client on the client be a object? an array? something else? Im pretty confused about these things and I don't want to mess anything up. Thanks in advance.
markr
markr
It really, really depends what kind of game you're making and how realtime it is etc.

In many (possibly even MOST) games, clients never speak directly to other clients. All updates go to the server and are re-sent to the other clients.

There are several good reasons for this - firstly it mitigates some forms of cheating, but mostly, it works much better with most firewalls in common use, especially NAT.

Even on games which support small "peer-to-peer" games, there is still a server. Just the server is just one of the players' machines.

The client and server run on the same machine, possibly as separate threads or processes (although not necessarily). The local client usually doesn't typically use network commands to talk to the local server, rather just directly sends updates through shared memory etc.

Some games use a local server even in single-player mode, for example, Quake, had a server which would run locally in singleplayer mode. Of course this server didn't actually use any real networking (sockets etc), but just talked directly to the client (they ran in the same process/thread anyway). The separation there was simply to make code reuse between the networked and non-networked modes easier.

In the very simplest case, the server just acts as a sort of relay, blindly accepting updates from clients and re-sending them to the other clients. The only other thing it needs to do is keep track of who's connected - ensuring that dead clients are kicked off etc.

Mark
bgilb
bgilb
Yeah sorry if I didnt write it good enough, but I was mostly talking about the code side of things..

I already have a server and client, the server uses threads for each client.

What im wondering is whats the most effecient way for the client program to handle clients? Should I use threads there too? or one thread for all the clients



( Ah sorry just realized this should have gone under network programming forum .. you can move it if you like :D, but its not really talking about network but more the structure the game uses to handle players)
hplus0603
hplus0603
This question belongs in the networking forum!

Also, the Forum FAQ of the networking forum will point you at some good starting links to read up on these things.
enum Bool { True, False, FileNotFound };
meeshoo
meeshoo
well, if i get it write, you got it wrong :). there are 2 main paradigms you can use: peer 2 peer and client/server. in the first one, each client comunicates with other clients, and in the second one each client is sending data about itself to the server, and the server collects the data and sends the data about all clients to each client. the second one is most suitable for games, because in this way the server can be a powerful dedicated computer, and the play stations don't need to have so much CPU power and network bandwith. so it's write to use threds for each client, on the serverside. so the comunication between the server and each client goes asynchroniuously. so each thread should have a timer. in case the server doesn't receive data from a client, after a while it can disconnect it. the client, if it doesn't receive data from the server for a while, it can use prediction, or other techniques:

ex: let's imagine a client receives data that a player runs in a direction. now if it doesn't receive new data to know what that player is doing, on the client side, the representation of that player will keep running, until new orders. or there can be an AI that takes the player until new data is received.
bgilb
bgilb
okay gotcha .. but should a client on the client program look like this: ( this is server/client not peer to peer )


class Client
{
public Client()
{
//new client
}
}


// on the client you would call Client newCl = new Client();
//etc

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.