Sign in to follow this  

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

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

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

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