I did a simple web socket communication with spring 4,STOMP and sock.js, following this https://github.com/rstoyanchev/spring-websocket-portfolio and this http://assets.spring.io/wp/WebSocketBlogPost.html
well, I want to know if is possible capture connection events like when a new client was connected to my server or when a client was disconnected, is that possible in Spring 4.0.0?
As I understand, the question with DISCONNECT event is not solved in this topic. Handshake interception gives you only connect info but not disconnect.
I have achieved this with the interceptors of inbound channel:
...and class...
Please note that Principal is available on CONNECT but not on DISCONNECT, however you have sweet Session ID
This an be done with a connection handshake interceptor (HttpSessionHandshakeInterceptor), quoting the documentation:
Spring WebSocket publishes events when messages are received from the client, if you are using STOMP, these are the events published:
The easiest way to detect connects and disconnects is by implementing an event listener for the mentioned events.
Here's a sample implementation that keeps track of connected users: https://github.com/salmar/spring-websocket-chat/blob/master/src/main/java/com/sergialmar/wschat/event/PresenceEventListener.java