I have client-server application, client is based on Java Desktop Application, and server is web application with endpoint exposed and deployed tomcat.
Does @OnClose
handles below scenarios. Can i send some message to server end point when it comes to @OnClose
method.
I need to handle scenario where client connection closes due to
1.) Internet drop connection
2.) System goes in Hibernate mode.
Server can have my clients connections open.
Here is my client code
@ClientEndpoint
public class ChatroomClientEndPoint {
Session session = null;
public ChatroomClientEndPoint() {
URI uri;
try {
uri = new URI("endpoint url");
ContainerProvider.getWebSocketContainer().connectToServer(this, uri);
System.err.println("Connection found");
} catch (Exception ex) {
System.err.println("No connection found-->" + ex);
}
}
@OnOpen
public void processOpen(Session session) throws MalformedURLException, IOException {
session.setMaxIdleTimeout(60000 * 60 * 24); //websocket session timeout =1 day
this.session = session;
}
@OnMessage
public void processMessage(String message) throws JSONException {
// on receiving messages from server, sends desktop notifications
}
public void disConnect() throws IOException {
sendMessage("close");
}
}
** This code is already developed, and i think they have not implemented @OnClose
because they send close message to the server, server then removes that session from its list.
Can @OnClose
help in case of above failures like these.