Jump to content
  • Advertisement
Sign in to follow this  
Rich76

Websocket: ping and pong to calculate latency. Anything special?

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

I want to calculate and display network latency on my game. Is there anything special about a ping request or a pong response, or is it the same as sending any data? I want the client to send pings to the server multiple times a second, and I want to make sure I'm doing it efficiently with little impact on the server (and the client). For example, do I just send the server a string "ping" and have the server respond back with a string "pong?"

 

 

Thank you

Share this post


Link to post
Share on other sites
Advertisement

I was able to find this:

 

 

 

Pings and Pongs: The Heartbeat of WebSockets

At any point after the handshake, either the client or the server can choose to send a ping to the other party. When the ping is received, the recipient must send back a pong as soon as possible. You can use this to make sure that the client is still connected, for example.

A ping or pong is just a regular frame, but it's a control frame. Pings have an opcode of 0x9, and pongs have an opcode of 0xA. When you get a ping, send back a pong with the exact same Payload Data as the ping (for pings and pongs, the max payload length is 125). You might also get a pong without ever sending a ping; ignore this if it happens.

 

http://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers

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!