2

I have a spring boot project in which I have implemented web sockets. I have not used STOMP, instead, I have implemented a TextWebSocketHandler which handles all the messages.


In order to handle session disconnection on network failure, I have made used of the ping pong scheme as follows as suggested in this thread handling-connection-loss-with-websockets

  • There is a periodic task which sends PingMessage to each WebSocketSession. I keep a flag for each session which indicates whether a pong has been received or not.
  • Before sending the ping message, I check whether I have received the pong for the previously sent ping, if not, then I close the session using the close() method of the WebSocketSession class
  • Upon receiving the pong message, I update the flag for the session

Now the problem is when I try to close a session, then other sessions are also being closed. I added some logs int the afterConnectionClosed() callback, and I can see that it is being triggered for sessions other than the one on which I called close() method.

I am not sure why this is happening.

Also, is there any other way by which I can handle connection loss in web sockets


The following is some information related to versions

  • Spring boot version 1.5.10.RELEASE
  • JDK 1.8
greenPadawan
  • 1,511
  • 3
  • 17
  • 30

0 Answers0