?
Solved

ping for client and server

Posted on 2007-10-18
5
Medium Priority
?
240 Views
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.
0
Comment
Question by:pcvii
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 20106027
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.
0
 
LVL 14

Expert Comment

by:wayside
ID: 20108933
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.
0
 
LVL 11

Expert Comment

by:Deepu Abraham
ID: 20114403
If you want more information on the ping status try WMI class
Win32_PingStatus Class
Best Regards,
DeepuAbrahamK
0
 

Author Comment

by:pcvii
ID: 20114764
ok i like some of the info

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

Accepted Solution

by:
jgordos earned 1000 total points
ID: 20227041
Sure.

Define some new messages for your api

Call the first one
GIMMIE_MY_PING
and the second one
HERES_YOUR_PING

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.


0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

840 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