Sign in to follow this  

Sdlnet ping

This topic is 2056 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

[quote name='Mr.L' timestamp='1335384951' post='4934875']
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.
[/quote]

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

This topic is 2056 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this