spring-guides / gs-messaging-stomp-websocket

Using WebSocket to build an interactive web application :: Learn how to the send and receive messages between a browser and the server over a WebSocket

Home Page:http://spring.io/guides/gs/messaging-stomp-websocket/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebSocket connect/disconnect Events

vw98075 opened this issue · comments

commented

The WebSocket connect/disconnect part doesn't seem to be completed in the back-end Java code. I add the following code to react when the connect button is triggered.

@component
public class WebSocketSessionListener implements ApplicationListener{

@Override
@EventListener
public void onApplicationEvent(SessionConnectEvent event) {
    // handle the connect event
    System.out.println("WebSocket session connected: " + event.getMessage().toString());
}

}

It detects the event, but the events of both connect and disconnect are fired twice for some reason.

commented

and has other methods ? such as the service active to disconnect the service.no the user to disconnect the service or how to do when the user disconnect . the service to do something ?

We keep the guides as simple as possible (because we want them to be completable in 15 minutes). You should ask that question on Stack Overflow.