Results 1 to 8 of 8

Thread: Synchronisation

  1. #1
    IRN-BRU(tm)
    Join Date
    Aug 2004
    Location
    Milton Keynes
    Posts
    484
    Thanks
    8
    Thanked
    9 times in 7 posts

    Synchronisation

    ok, i need to synchronise two devices down to the nearest millisecond, they are connected over a network, i can get the current time from the device in milliseconds.

    i know there is a simple answer im just being silly.

    I was thinking something along the lines of device A sends its current time to device B, device B sends the time received and its current time back to A and A works out the difference and adds it to its time. but this doesnt garauntee synchronisation of the clocks. as it will depend on how long it took to connect which can be as short as 1 second and as long as 10 seconds in either direction (its an unreliable network).

    some clever monkey please help me

  2. #2
    Registered+ Zathras's Avatar
    Join Date
    Jul 2003
    Location
    Canary Wharf/Richmond
    Posts
    1,454
    Thanks
    13
    Thanked
    7 times in 4 posts
    Use some implementation of NTP? http://www.ntp.org/

  3. #3
    IRN-BRU(tm)
    Join Date
    Aug 2004
    Location
    Milton Keynes
    Posts
    484
    Thanks
    8
    Thanked
    9 times in 7 posts
    i dont actually want to synchronise the time, i want both devices to pop up a message at exactly the same time, so need to precalibrate them to ensure this happens. thanks for the suggestion, as ntp is open source i will read through it and see if there is anything i can use. ta

  4. #4
    DsW
    DsW is offline
    Senior Member
    Join Date
    Aug 2003
    Location
    Glasgow
    Posts
    292
    Thanks
    0
    Thanked
    0 times in 0 posts
    If you make one machine the NTP server then the other can synchronise to it.

    Both will be running the same time and therefore will be able to pop up the dialog at exactly the same time (or as near to the same time as possible).

    Another way of doing it is to get one device to make a call to the other when it wants to pop up the dialog and then pop up its own dialog when the call returns.

    cheers,
    dave

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    13
    Thanks
    0
    Thanked
    0 times in 0 posts
    I don't think it's possible to synchronise within milliseconds, two independent devices on a network, however, you could have a separate machine, which connects to a time server, which then sends a network message to each device, or uses some proprietary method of remote execution such as rcmd, or DCOM on the Windows platform or a custom-written application using sockets. It depends on the acceptable margin of error. If it doesn't matter so much, do as has been suggested, and have one of your machines as an NTP server for both devices, even if one device is local to the server running NTP.

  6. #6
    Member
    Join Date
    Aug 2003
    Posts
    183
    Thanks
    0
    Thanked
    3 times in 2 posts
    I think it must be possible. Firstly you need to work out how long it takes machine A to send a message to machine B. To do this get them both to synchronise with an external NTP server. Then get machine A to ping machine B with it's time. Machine B will then know (1) what time it thinks it is, and (2) what time that machine A thinks it is. It can then work out what the time difference is, and therefore what the time taken for A to send a message to B. If you do this frequently over a period of time (and using all results to take an average) then you should iron out individual poor responses.

    It isn't perfect because A may take longer to get the time than B. But over a period of time the average should be reasonably accurate. It probably won't be accurate to a millisecond but should be reasonably accurate.

    Once you have the average time taken to send a message between the machines then just pick one as te master and the other as the slave. The slave then sets its time to the masters and can take into account the latency of the connection.

    I think? Can anyone seen any glaring problems with that?
    Last edited by Hades; 28-12-2004 at 08:24 PM.

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    13
    Thanks
    0
    Thanked
    0 times in 0 posts
    The simple fact is that if you're trying to synchronise two devices over an unreliable link where communication granularity is in the order of milliseconds, you cannot expect synchronisation to be achieved with the same level of granularity. I've no doubt there is a way, but it will be non-trivial (dedicated link) or will require a more esoteric communication protocol than humble TCP/IP.

    We need to know how critical the synchronisation is anyway. Personally, I doubt there's really much call for it having a granularity of milliseconds if it's for a user interface dialog to be displayed to users as surely we'd also have to take into account the reaction time of the user as well. It's also important to remember that we may have no control over how many "hops" are made for our TCP/IP communication...
    Last edited by phykell; 28-12-2004 at 08:54 PM.

  8. #8
    IRN-BRU(tm)
    Join Date
    Aug 2004
    Location
    Milton Keynes
    Posts
    484
    Thanks
    8
    Thanked
    9 times in 7 posts
    hey guys, some interesting ideas and suggestions thanks very much, i think i will try as Hades suggests using the average latency. As to the criticality of the synchronisation, the application is a peer to peer Texas Cowboy Shootem Up on a mobile phone.

    Two phones will connect to each other over bluetooth/ GPRS and synchronise thier clocks. When the screen changes colour the players must press a button on their handsets to 'fire' a bullet at the other phone, quickest reaction wins! If you have an itchy trigger finger and press too early you miss and lose, to late and you get shot!

    The synchronisation is quite critical to the feel of the shooting - if both phones do not trigger at the same time, players will dispute the results of the reaction time. Functionally the sychronisation will not matter as the phones can send each other the other player's reaction time to the nearest milli calculated from the time of trigger to the the time of keypad event.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •