Network updates: how frequent

Discussion about everything. New games, 3d math, development tips...
Post Reply
JPulham
Posts: 320
Joined: Sat Nov 19, 2005 12:06 pm

Network updates: how frequent

Post by JPulham »

I have a network game where a pllayer gives the server its updates and then its update is resent to each client, but how often should I send an update from a client? every second? every half second? more? less?
How do I decide?
pushpork
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

How about sending on event! Like if the player moves then send an update that the player moved to here!
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

what kind of game? a live action game? like Rapchik said, you shouldn't send any information back and forth where it isn't required, it makes no sense to have messages sent at fixed intervals.
look up dead reckoning, the basic algorithm is this-
- send event from client to server (ie, button is pressed for movement)
- client waits half ping time (ping = round trip time)
- start movement event on client in anticipation of server's response (completely fake to make it look nice)
- server recieves message at the same time and sends a message back confirming new speed, heading, position
- half ping time passes...
- client recieves message, and if it was guessed correctly, there will be no difference and the movement is smooth
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

How about updating on event! Like if the player moves then send an update that the player has moved to some location!
JPulham
Posts: 320
Joined: Sat Nov 19, 2005 12:06 pm

Post by JPulham »

Its a FPS
Hmm. Thats an Idea. I'll look into it.
BTW. How do I find half a ping time?

now I have work to do
* googles dead reckoning *
pushpork
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

How do I find half a ping time?
Send a packet with the current time and a sequence number to the other client. When that client receives that packet, it immediately sends a response that includes the data from the packet it received. When you receive the response, verify the sequence number and record the time when that packet arrived. If you subtract times, you'll get the round-trip-time. Divide that by two. You'll want to update the ping statistics periodically because they can change based on external events.

You use the sequence number so that you don't use a stale ping response for calculating the round-trip-time.

Travis
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Also, you'll probably want to use UDP for doing your pings. If you use TCP, the packet may be resent automatically or held up in the driver which can mess up your ping times. UDP is unreliable, so you may never receive a response for a particular request. Even if you do receive a response, it may come out of order, but that is why you used the sequence number in the first place.

Travis
Post Reply