6

I have a websocket client in python implemented using tornado.websocket. WebSocketClientConnection which connects to a server at remote end and communicate over websocket. Earlier I had implemented the ping/pong like feedback mechanism at application layer to ensure if the remote endpoint is still responsive.

I just recently updated my tornado package and I came across the ping_interval in WebSocketClientConnection. I removed the old ping/pong mechanism at application layer and added this ping_interval in my implementation.

After this updates the websocket is getting closed after the mentioned ping_interval timeout. The server at remote end handles the ping at transport layer and respond accrodingly.

  1. currently I have not implemented the ping method so should I have to implement ping method for WebSocketClientConnection?,
  2. should I have to send any data in ping method?
  3. do I have to implement any method to handle the response send by remote server for the ping request?

1 Answer 1

6
  1. No, It's implemented by default.
  2. You may but don't have to.
  3. I assume that by response you've ment pong. If you're using ping_interval you don't have to process pong, but if you're sending pings manually you have to control timeouts by yourself so you have to process pongs by implementing tornado.websocket.WebSocketClientConnection.on_pong method.
2
  • hi @Fian, if my server is also tornado and implements websocket using WebSocketHandler, does WebSocketHandler also have to send pong to handle the pings sent using WebSocketClientConnection? Sep 12, 2018 at 12:46
  • Both WebSocketClientConnection and WebSocketHandler are based on WebSocketProtocol13 class which does periodic pings by default and finishes connection if pong is not received in ping_interval time.
    – Fine
    Sep 12, 2018 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.