ping for client and server

Posted on 2007-10-18
Last Modified: 2010-04-01
I'm writing a lobby client and server system. for hosting games and stuff. I want the client to know how good their ping is to the server. or to the games being hosted.

I'm using SDL and SDLnet. I was thinking of using time. But I was unsure of how to do that because my clients could be in another time zone or have their computers just with different times on them.

I'm coding in visual studio 2005 express.
Question by:pcvii
    LVL 86

    Expert Comment

    Just use - the time zones should not matter, since the respose times should be seconds in the worst case.
    LVL 14

    Expert Comment

    That project uses raw sockets to do the ping. This is not reliable because the latest Microsoft OS's can deny access to raw sockets depending on your privileges.

    Better is to use the IcmpSendEcho function as shown here:

    This will work no matter what your privileges.
    LVL 11

    Expert Comment

    If you want more information on the ping status try WMI class
    Win32_PingStatus Class
    Best Regards,

    Author Comment

    ok i like some of the info

    any ideas how i could use the tcp connection thats already established?
    LVL 11

    Accepted Solution


    Define some new messages for your api

    Call the first one
    and the second one

    When the client builds and sends GIMMIE_MY_PING, he timestamps the message

    The server gets it, and replies with HERES_YOUR_PING... but he copies the timestamp from GIMMIE_MY_PING into the HERES_YOUR_PING response

    When the client gets the HERES_YOUR_PING message, he takes his current time and subtracts out the time contained in the HERES_YOUR_PING response.

    The time represented is the ROUND TRIP Time.  

    Close enough to the ping for government work, and has the benefit of being server time independent, and representative of your actual load.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now