Disconnect client session from Spring websocket stomp server
spring, spring-boot, spring-websocket, stomp
Solution
As far as I know the API doesn't provide what you are looking for, on server-side you can only detect disconnect events. If you want to disconnect a certain client I think you must go for a litte workaround, e.g. this one:
- Write a client-side javascript function that is able to trigger a disconnect
- As soon as your client is connected to the server, generate a client ID in your javascript and send it to the server. Remember the ID on the client, you'll need it in step (4).
- At the time you want the server to disconnect the connection to the specific client (identified by the ID), send a message containing the ID back to the client.
- Now your client javascript evaluates the message send from the server and decides to call the disconnect function you wrote in step (1).
- Your client disconnects itself.
The workaround is a bit cumbersome but it'll work.
Problem
I've searched quite a bit and been unable to find this: Is there a way that a spring websocket stomp server can disconnect a client based on the sessionId (or really based on anything at all)? It seems to me that once a client connects to a server there is nothing that allows the server to disconnect the client.