Thread: Calculate ping

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905

    Calculate ping

    Here's the problem, I've got a program where i'm trying to synchronize 2 sounds at once by sending the current position in the song on the server to the client, but it gets offset by a little bit cuz of the time it takes to send from the server to the client.....how do i calculate this time? I'm rather new to winsock and I've tried doing a simple GetTickCount, but of course, the two ticks were different, so that won't work at all.

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    9
    Encode your system time in a packet. Send that packet to the recipient. Have the recipient send it back to you. Subtract the current time from the system time in the packet.

  3. #3
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    Here's the problem, I've got a program where i'm trying to synchronize 2 sounds at once by sending the current position in the song on the server to the client, but it gets offset by a little bit cuz of the time it takes to send from the server to the client.....how do i calculate this time? I'm rather new to winsock and I've tried doing a simple GetTickCount, but of course, the two ticks were different, so that won't work at all.
    well, what I would do is as Rak'Kar said, add a timestamp to your packet; however, I would also suggest making a "fuller" packet by having a packet such as:

    struct soundPacket
    {
    unsigned int SONG_ID; // ID of song, used to index into your song list
    unsigned int SONG_TIME; // current time of song, in milliseconds
    }
    reason being is that during synchronization, the recipients song might not have changed yet so you might have the following:

    server : playing SONG_ID = 2, SONG_TIME = 1000
    recipient : playing SONG_ID = 1, SONG_TIME = 1000

    in this case, if you dont add a time stamp, and even if you did, the song would still be wrong and you might just keep rolling the song over.
    Last edited by EvBladeRunnervE; 07-09-2004 at 11:55 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ping script doesn't work?
    By userpingz in forum C Programming
    Replies: 3
    Last Post: 05-31-2009, 07:53 PM
  2. Replies: 8
    Last Post: 05-07-2009, 11:31 AM
  3. IPv6 ping in windows...problem..lots of ode:(
    By Neill KElly in forum C Programming
    Replies: 3
    Last Post: 04-27-2009, 11:50 PM
  4. ping client
    By cpp_is_fun in forum C Programming
    Replies: 4
    Last Post: 11-29-2006, 12:44 PM
  5. Small program that has to calculate miles per gallon
    By Guti14 in forum C++ Programming
    Replies: 6
    Last Post: 01-06-2004, 02:47 PM