Example #1
0
 @Override
 public void close(CloseReason closeReason) throws IOException {
   if (closed.compareAndSet(false, true)) {
     try {
       if (closeReason == null) {
         endpoint
             .getInstance()
             .onClose(this, new CloseReason(CloseReason.CloseCodes.NO_STATUS_CODE, null));
       } else {
         endpoint.getInstance().onClose(this, closeReason);
       }
       if (!webSocketChannel.isCloseFrameReceived()) {
         // if we have already recieved a close frame then the close frame handler
         // will deal with sending back the reason message
         if (closeReason == null) {
           webSocketChannel.sendClose();
         } else {
           WebSockets.sendClose(
               new CloseMessage(
                       closeReason.getCloseCode().getCode(), closeReason.getReasonPhrase())
                   .toByteBuffer(),
               webSocketChannel,
               null);
         }
       }
     } finally {
       close0();
     }
   }
 }
  @OnClose
  public void onClose(final Session session, final CloseReason reason) {

    System.out.println(" --------------------------------------------------------------------- ");
    System.out.println(" WsCommunicationsTyrusCloudClientChannel - Starting method onClose");

    try {
      switch (reason.getCloseCode().getCode()) {
        case 1002:
        case 1006:
          raiseClientConnectionLooseNotificationEvent();
          System.out.println(" WsCommunicationsTyrusCloudClientChannel - Connection loose");
          break;

        default:
          if (reason.getReasonPhrase().contains("Connection failed")) {
            raiseClientConnectionLooseNotificationEvent();
          } else {
            raiseClientConnectionCloseNotificationEvent();
            setIsRegister(Boolean.FALSE);
          }

          break;
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #3
0
  private void sendCloseMessage(CloseReason closeReason) {
    // 125 is maximum size for the payload of a control message
    ByteBuffer msg = ByteBuffer.allocate(125);
    CloseCode closeCode = closeReason.getCloseCode();
    // CLOSED_ABNORMALLY should not be put on the wire
    if (closeCode == CloseCodes.CLOSED_ABNORMALLY) {
      // PROTOCOL_ERROR is probably better than GOING_AWAY here
      msg.putShort((short) CloseCodes.PROTOCOL_ERROR.getCode());
    } else {
      msg.putShort((short) closeCode.getCode());
    }

    String reason = closeReason.getReasonPhrase();
    if (reason != null && reason.length() > 0) {
      appendCloseReasonWithTruncation(msg, reason);
    }
    msg.flip();
    try {
      wsRemoteEndpoint.startMessageBlock(Constants.OPCODE_CLOSE, msg, true);
    } catch (IOException ioe) {
      // Failed to send close message. Close the socket and let the caller
      // deal with the Exception
      WebsocketsLogger.ROOT_LOGGER.closeMessageFail(ioe);
      wsRemoteEndpoint.close();
      // Failure to send a close message is not unexpected in the case of
      // an abnormal closure (usually triggered by a failure to read/write
      // from/to the client. In this case do not trigger the endpoint's
      // error handling
      if (closeCode != CloseCodes.CLOSED_ABNORMALLY) {
        localEndpoint.onError(this, ioe);
      }
    } finally {
      webSocketContainer.unregisterSession(localEndpoint, this);
    }
  }
 /**
  * クライアントの切断時にコールされる
  *
  * <p>引数は前述の通り、省略可能
  *
  * @param client 接続
  * @param reason 切断理由
  */
 @OnClose
 public void onClose(Session client, CloseReason reason) {
   System.out.println(
       client.getId()
           + " was closed by "
           + reason.getCloseCode()
           + "["
           + reason.getCloseCode().getCode()
           + "]");
 }
    @Override
    public void close(CloseReason reason) {
      if (socket.isConnected()) {
        socket.close(reason.getCloseCode().getCode(), reason.getReasonPhrase());

        for (Extension extension : endpoint.getSupportedExtensions()) {
          if (extension instanceof ExtendedExtension) {
            try {
              ((ExtendedExtension) extension).destroy(extensionContext);
            } catch (Throwable t) {
              // ignore.
            }
          }
        }
      }
    }
Example #6
0
 @Override
 public void onClose(Session session, CloseReason closeReason) {
   MaxSessionPerRemoteAddrApplicationConfig.closeLatch.countDown();
   if (closeReason.getCloseCode().getCode() == CloseReason.CloseCodes.TRY_AGAIN_LATER.getCode()) {
     forbiddenClose.set(true);
   }
 }
  /**
   * deprecated: 接收到客户端关闭时调用
   *
   * <p>date 2015-03-06
   *
   * @author sharkTang
   * @param session
   * @param closeReason
   */
  @OnClose
  public void onClose(Session session, CloseReason closeReason) {
    try {
      logger_.info(
          "Web-socket session "
              + session.getId()
              + "  sessionHashCode"
              + session.hashCode()
              + " closed, reason: "
              + closeReason.toString());
      WebSocketManager.webSocketClientCount--;
      WebSocketManager.webQueryStringSet.remove(session.getQueryString());
      // 关闭客户端 赋值全局session,并删除websocket对象
      webSocketAction(webSocketMap, session, WebSocketConstants.REMOVE_STR, null);
      daPingWebsocketSession = session;
      webSocketMapAction(webSessionMap, session, WebSocketConstants.REMOVE_STR);
    } catch (Exception ex) {

    }
  }
Example #8
0
 @Override
 public void onClose(Session session, CloseReason closeReason) {
   WebSocketDelegate.this.onClose(
       closeReason.getCloseCode().getCode(), closeReason.getReasonPhrase());
 }
Example #9
0
 @OnClose
 public void onClose(CloseReason close) {
   System.out.printf(
       "Closed: %d, \"%s\"%n", close.getCloseCode().getCode(), close.getReasonPhrase());
   closeLatch.countDown();
 }