Jump to content
  • Advertisement
Sign in to follow this  
Mr.L

Sdlnet ping

This topic is 2271 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how can i get the ping (Latency) of a host in sdlnet?


believe me I've thaught a lot about it, before i've postet it.

Share this post


Link to post
Share on other sites
Advertisement

how can i get the ping (Latency) of a host in sdlnet?


believe me I've thaught a lot about it, before i've postet it.


have the client send a packet to the server, and record the time at which the packet is sent, have the server send a reply, have the client record the time at which the reply arrives, output the difference.

Share this post


Link to post
Share on other sites
but there's a problem:
i've the code is somthing like this
[font=courier new,courier,monospace]void main(){[/font]

[font=courier new,courier,monospace]double ping;[/font]
[font=courier new,courier,monospace]bool sentstate=true;[/font]
[font=courier new,courier,monospace]while(true){[/font]
[font=courier new,courier,monospace] work_0.02_seconds();[/font]
[font=courier new,courier,monospace] double sincesent=getmils();[/font]
[font=courier new,courier,monospace] checksockets(socks);[/font]
[font=courier new,courier,monospace] if (socketready(sock1)&&sentstate){[/font]
[font=courier new,courier,monospace] send("ping");[/font]
[font=courier new,courier,monospace]sendstate=false;[/font]
[font=courier new,courier,monospace] }[/font]
[font=courier new,courier,monospace] if (socketready(sock1)&&!sentstate){[/font]
[font=courier new,courier,monospace]char[123] buffer; [/font]
[font=courier new,courier,monospace]receive(buffer);[/font]
[font=courier new,courier,monospace]if (buffer=="pong"){[/font]
[font=courier new,courier,monospace]ping=getmilis()-sincesent;[/font]
[font=courier new,courier,monospace] [/font]
[font=courier new,courier,monospace]}[/font]
[font=courier new,courier,monospace]sendstate=false;[/font]
[font=courier new,courier,monospace] }[/font]

[font=courier new,courier,monospace] }[/font]
[font=courier new,courier,monospace]}[/font]
then the ping isn't very exakt, so for example it could never be under 0.02 seconds.
but games can be under 20 milisecond, or have i misunderstood something?

Share this post


Link to post
Share on other sites
Note that the effective ping time includes the latency of the client and the server.

Another option is to send "client timestamp" with the ping message. The server, when receiving it, stores "client timestamp" plus "server timestamp" when it first receives the message. Once it handles the message and sends a reply, it sends "(server new timestamp - server receive timestamp)" and "client original timestamp" in the message. The client, finally, receives the packet, and can timestamp it, and compare to the original timestamp. Subtract the server working time (the difference between server timestamps) from the client timestamp difference, and divide by two; that's a good approximation of the actual latency between client and server processes.

If you for some reason want to avoid including the processing overhead (even though that's something that will always affect actual latency,) you can use high-priority threads on server and client for receiving/timestamping packets.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!