How do you quickly close a nonresponsive websocket in Java Spring Tomcat?

后端 未结 4 1110
鱼传尺愫
鱼传尺愫 2021-01-11 15:09

I have a real-time application with clients using websockets to connect with a Spring Framework server, which is running Spring Boot Tomcat. I want the server to quickly (wi

4条回答
  •  -上瘾入骨i
    2021-01-11 15:17

    The approach I eventually took was to implement an application-layer ping-pong protocol.

    • The server sends a ping message with period p to the client.
    • The client responds to each ping message with a pong message.
    • If the server sends more than n ping messages without receiving a pong response, it generates a timeout event.
    • The client can also generate a timeout event if it does not receive a ping message in n*p time.

    There should be a much simpler way of implementing this using timeouts in the underlying TCP connection.

提交回复
热议问题