• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

ping for client and server

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.
1 Solution
Just use http://www.codeproject.com/internet/winping.asp - the time zones should not matter, since the respose times should be seconds in the worst case.
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: http://msdn2.microsoft.com/en-us/library/aa366050.aspx

This will work no matter what your privileges.
Deepu AbrahamR & D Engineering ManagerCommented:
If you want more information on the ping status try WMI class
Win32_PingStatus Class
Best Regards,
pcviiAuthor Commented:
ok i like some of the info

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

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now