/* attempt to deal with prototype, bootstrap, jquery conflicts */ /* for dropdown menus */

Jump to content

Image of the Day

Day 17 -- a bunch more tools join the table :) #blender3d #screenshotsaturday #itssaturdaysomewhere #lowpoly #3D https://t.co/CYJucn0Lfv
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.

Sign up now

Client-Server network and physics collision

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 JacopoMTK   Members   


Posted 25 March 2013 - 03:20 AM

Hi everyone,


I want to build a small client-server network for a spaceship game using TCP [to simplify things].

I'm kind of new on game network programming so i searched a bit on the web and it seems to me that

the easiest implementation is quake 3-like network algorithm.


note:a easy-to-program solution is preferable to one with high performance (within limits of course)


I was thinking to let the server manage the REAL state of the game and send information of it to the clients.

Meanwhile,clients only send "controller input data" for example

"client X has pressed button01" that mean he want to move forward etc.

"client X has pressed button02" that mean he want to fire primary weapon and so on.


Thinking about this,since it's my first experience in this kind of programming i've some question that come to mind:

-It should be safe since all the physics is managed on the server side.

-Sending input data without prediction on the client side and waiting for the server response for the new state

 could deliver a strong lag on player having high ping: if player X has 150ms of ping,when he press the move button

 he will actually start moving 300ms later [client-srv   //position computation//  srv- client]

-What's the best way to synchronize packets? I was thinking about sending a timestamp withing each packet

but,what will this time is referred to? I can't use local machine time since it could be different and...

will be a time synchronization (to a webserver for example) be reliable with some millisecond precision?



Can you guys please give me some opinions on those points?

Will the "send input to server" system hit so hard on performance?


Thanks in advance.


#2 bb_buster   Members   


Posted 25 March 2013 - 05:08 AM

As you've pointed out the problem with sending the inputs to the server is they take time for the server to process and return the result.

What you can do is send the key press to the server and then stimulate the key press immediately on the client. Then the server predicts the movement and possible future position of where it expects the player to be and sends the info back to the client which can use this data along with its current position data to work out its location.

I know you said for simplicity to keep it TCP but if packets are supposed to be sent often then id recommend using a UDP socket instead as TCP sends a message to the server which processes it then sends a confirmation message its been received. UDP just sends the message without waiting around for that confirmation back making it much quicker

Hope that helps with your problem

#3 Ashaman73   Members   


Posted 25 March 2013 - 06:14 AM

I want to build a small client-server network for a spaceship game using TCP [to simplify things].

There are several topics:

1. tcp/udp

2. client prediction

3. lag hidding


1. starting with tcp isn't a bad idea, just remember, that tcp is a stream . The disadvantage is, that you will send every information in the right order through the tcp channel, even if the data are already obsoleted by newer data. Best to think already in packets/messages, even when using tcp, so that you can switch to udp or a tcp/udp hybrid more easily later on.


2. Client prediction helps to smooth fast paced action experiences. If you have e.g. a relative slow moving spaceship game, prediction might not be needed at all, therefor test it out without client prediction first.


3. Lag hidding is an other option. E.g. you can use delayed actions to hide the lag. Press the button to fire a missile, the fireing of the missile have a delay of 2 seconds, because the missile bay needs to be opened (a sound plays).  Even if the missile bay opening sound starts later and it is not exactly 2 seconds after pressing the button, that the missile starts, the player will most likely not recognise the lag. There are other options to hide it, e.g. a laser tower which needs to track the target etc. Sometimes starting the visual/audio effects when pressing the button (e.g. laser effect) is enough to hold up the illusion of a lag-less game experience.



Gnoblins: Website - Facebook - Twitter - Youtube - Steam Greenlit - IndieDB - Gamedev Log

#4 JacopoMTK   Members   


Posted 25 March 2013 - 07:55 AM

Thanks to both for the reply!smile.png



So i start moving without waiting the server and eventually fix the position depending on the server response?


I had in mind to use UDP but i don't want to get a lot of problem due to data loss since,for what i know,they're pretty tricky to find.

Anyway it should be possible to switch to UDP by implementing an ack solution.




1. Sure,using packets is the idea.

2. The problem is that,those ships don't move slowly,i hope that it could be solved by using an high priority on the position check.

As you said,i'll test it out without prediction first.

3. Oh god...that's so simple as smart!I didn't thought about masking the lag in that way,thanks!



Oh another thing,what is a normal update time of the network?

I suppose to have to transfer data from the client to the server only when the user do something but what about

the other way?

Every how many update cycles should i transfer the data from server-->client to update other players position etc?

(having for example 60 update call per second)


Thanks again.

#5 hplus0603   Moderators   


Posted 25 March 2013 - 02:21 PM

A typical update rate on consoles is 15 times a second. This means data for 4 simulation ticks is included in each update. It also means you add up to 70 milliseconds of "artificial" lag compared to a 60 Hz network rate. You do save a lot of bandwidth, though, which is important for console certification.

High-performance Counter-Strike servers may run at 60 Hz or even 100 Hz network rate. It's unlikely that most games will find that to be a useful trade-off, though. More than 30 Hz for network packets is usually not warranted, and 20 Hz is often quite sufficient even for action games.
enum Bool { True, False, FileNotFound };

#6 JacopoMTK   Members   


Posted 25 March 2013 - 03:55 PM

Thanks for the detailed answer,i'll do some testing between 15-20 Hz

And thanks for pointing out the lag issue.

I don't know how much it effects the network state but it's good you pointed it out.

In the end that computational lag should be masked since every client will have the same 70ms offsett (plus the connection lag).



Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.