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.spri
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.
public class WebSocketEventListener {
@EventListener
private void handleSessionConnected(SessionConnectEvent event) {
...
}
@EventListener
private void handleSessionDisconnect(SessionDisconnectEvent event) {
...
}
}
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