Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

yct

synchronizing computers in a network

This topic is 5203 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Synchronizing computers seems to me essential in every network game; however i haven''t found an article that explains how to do it. For example, I need to know whether some event in computer A happened before some event in computer B. As I don''t know how long it takes a packet to be transmitted between the computers, I can''t figure out a way to do it. Any idea?

Share this post


Link to post
Share on other sites
Advertisement
If you really need to keep track of such things you could send a timestamp along with the data sent. That means, you have computer A send its local time along with the event.
When computer B receives the packet, it knows when the event has occured on computer A (assuming that both have the same base for time ...).

If they do not have the same base (which most likely they won''t have), you could define some sort of "virtual" clock (like number of milliseconds since connection was established ...). this way you can make sure that differences like GMT+1, GMT+5 etc. won''t have a negative impact.
Of course, this system also doesn''t work totally accurate, but I think it should be fairly enough for a game...

Hope that helped!

Indeterminatus

--si tacuisses, philosophus mansisses--

Share this post


Link to post
Share on other sites
I agree that the best way is to keep a clock on both computers. It''s also important that you synchronize them periodically to avoid problems like the ones that appeared in multiplayer Descent.. players would sometimes wind up with completely different scores.

Share this post


Link to post
Share on other sites
Check out the resources section of this page, as well as www.gamasutra.com (you''ll have to scroll way down the articles list to articles from 2000 or 2002 I believe)

*Lots* of great stuff to be read just sitting and waiting for your eyes.
I have recently spent a lot of time re-reading all the articles I have collected over the last four or so years and I have found it quite informative (its surprising how much info you can get from articles you have already read!)

Anyway, good luck.
- Jacob

Share this post


Link to post
Share on other sites
If there was some universal clock that both computers use, of course there would be no problem. For example, if I could synchronize both computers to UTC (but it has to be very accurate), there would be no problem. In this case the question is - how do I get UTC in a very good accuracy?

But i''m sure there has to be some decent alternative. If I wanna play a game in a LAN which isn''t connected to the internet, UTC is no help. I can''t just start a virtual clock when the connection between the computers is established, because the computers won''t know at the same time that a connection was established. In this case the question is still - what do I do?

Share this post


Link to post
Share on other sites
You could syncronise all the clients to the server clock.
To obtain the clock you could do this:

First, send a packet request for time sync with the server.
Save the time where this packet was sent.

Then when you receive the packet from the server with his clock time, you check at what time you received it.
You substract the time you received it with the time you sent the first packet and you divide by 2.
Then you substract this from the server clock time you received in the server packet.

This will give you the server clock time, but I believe there might be a difference of some milliseconds between the real server clock time and the clock time you have calculated.
So you could repeat this 4-5 time and do an average to find a more accurate time...


I never tested it, it''s just an idea and it might suck...

Share this post


Link to post
Share on other sites
Thanx Hedos. For now this is the only solution I have; I wonder if this is what real games do. I hope that the time it takes a packet to get from computer A to computer B is the same as the time it takes a packet to get from computer B to computer A, otherwise it''s no good to divide in 2...

Share this post


Link to post
Share on other sites
Kaludas - is NTP good only for synchronizing with time server or also synchronize between compures in a LAN/WAN? And do u know any friendly tutorials about using it?

Share this post


Link to post
Share on other sites
In order to synchronize machines on a LAN, you define one as a server, and slave the others off that. Bonus points if you get the server to in turn sychronize off some higher-tier time server, so they''re all in sync with the world, but that''s not strictly necessary.

Share this post


Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!