1
\$\begingroup\$

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!

\$\endgroup\$
1
  • \$\begingroup\$ Can anyone help plz? \$\endgroup\$
    – Trixmix
    Nov 10, 2012 at 11:19

2 Answers 2

2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ +1 for the link to Gaffer On Games' articles. Definitely the best online source for introductory game networking programming. \$\endgroup\$ Nov 11, 2012 at 6:01
1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .