title: Websockets - onclose - server/client - internet connection drop
body: <p>I have <strong>client-server application</strong>, <strong>client is based on Java Desktop</strong> Application, and <strong>server is web application with endpoint exposed</strong> and deployed tomcat.</p>
  
  <p><strong>Does <code>@OnClose</code> handles below scenarios.</strong> Can i send some message to server end point when it comes to <code>@OnClose</code> method.</p>
  
  <p>I need to handle scenario where client connection closes due to </p>
  
  <p>1.) Internet drop connection</p>
  
  <p>2.) System goes in Hibernate mode.</p>
  
  <p>Server can have my clients connections open.</p>
  
  <p>Here is my client code</p>
  
  <pre><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--&gt;" + 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");
      }
   }
  </code></pre>
  
  <p>** This code is already developed, and i think they have not implemented <code>@OnClose</code> because they <strong>send close message</strong> to the server, server then removes that session from its list.</p>
  
  <p>Can <code>@OnClose</code> help in case of above failures like these.</p>