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 want to know what is the logic behind server client communication through packets for a real time game. for example the server sends x packets then the client receives x packets and processes them..

Basically what is the process to keep the client and server in sync and able to receive and send packets.

more in depth example of what I want to know:

client

step 1 wait for a packet

step 2 read x packets

step 3 process x packets

step 4 send x packets

and so on...

I need to know the very basic outline of the communication.

Big questions are:

1) do I send and read packets all at one time? i.e for loop though the incoming packets array list and read them all or one every server loop or what...

2) what order should I do things i.e first receive then read then process then send etc..

3) what I asked above a step by step of what the server / client should do..

Thanks!

share|improve this question
    
Can anyone help plz? –  Trixmix Nov 10 '12 at 11:19
add comment

2 Answers

up vote 2 down vote accepted

1) You have a poll loop which checks for incoming packets, if you receive a packet you usually have to check if you want to accept that packet, decrypt it since you usually have some kind of encryption in order to protect the data. Then you analyse what kind of information is stored in this packet and depending on the content proceed with it

2) You usually use non-blocking sockets. This means you are sending and receiving packets all the time. But in many cases an incoming packet triggers one are many outgoing packets (e.g. position update)

3) Depends on your game and architecture.

Read all articles on http://gafferongames.com/ These are the best written articles for bloody beginners from my point of view.

share|improve this answer
    
+1 for the link to Gaffer On Games' articles. Definitely the best online source for introductory game networking programming. –  Sean Middleditch Nov 11 '12 at 6:01
add comment

Client -> Awaiting Gamestate

Server -> sending Gamestate to Client

Server -> Setting Position and Whatever ( depends how you divide the tasks for Client-Server-Model) -> sending to Client Client -> Sends Player movement to server

Server -> Sends Playermovement to other players

another point: You cannot keep everything synchronous , games often use asynchronous communication models.

share|improve this answer
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.