private void handleCloseFrame(ChannelHandlerContext ctx, CloseWebSocketFrame cwsf) { if (closed.compareAndSet(false, true)) { CloseReason cr = new CloseReason(cwsf.statusCode(), cwsf.reasonText()); handleCloseReason(ctx, cr); } }
public void handle(final Object msg) { ready(); if (msg instanceof TextWebSocketFrame) { onTextCallback.accept(((TextWebSocketFrame) msg).text()); } else if (msg instanceof BinaryWebSocketFrame) { onBinaryCallback.accept(((BinaryWebSocketFrame) msg).content().nioBuffer()); } else if (msg instanceof CloseWebSocketFrame) { CloseWebSocketFrame closeFrame = ((CloseWebSocketFrame) msg).retain(); int statusCode = closeFrame.statusCode(); onCloseCallback.accept(statusCode == -1 ? WebSocket.NORMAL.code() : statusCode, Optional.ofNullable(closeFrame.reasonText())); handshaker.close(ctx.channel(), closeFrame).addListener(CLOSE); } else if (msg instanceof Throwable) { onErrorCallback.accept((Throwable) msg); } }
CloseWebSocketFrame closeFrame = new CloseWebSocketFrame(frame.statusCode(), frame.reasonText()); chctx.writeAndFlush(closeFrame).addListener(ChannelFutureListener.CLOSE); closeFrameSent = true;
public void handleFrame(WebSocketFrame frame) { if (frame instanceof TextWebSocketFrame) { onTextFrame((TextWebSocketFrame) frame); } else if (frame instanceof BinaryWebSocketFrame) { onBinaryFrame((BinaryWebSocketFrame) frame); } else if (frame instanceof CloseWebSocketFrame) { Channels.setDiscard(channel); CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame; onClose(closeFrame.statusCode(), closeFrame.reasonText()); Channels.silentlyCloseChannel(channel); } else if (frame instanceof PingWebSocketFrame) { onPingFrame((PingWebSocketFrame) frame); } else if (frame instanceof PongWebSocketFrame) { onPongFrame((PongWebSocketFrame) frame); } else if (frame instanceof ContinuationWebSocketFrame) { onContinuationFrame((ContinuationWebSocketFrame) frame); } }
CloseWebSocketFrame frame = (CloseWebSocketFrame) msg; assertEquals(status, frame.statusCode()); assertEquals(reason, frame.reasonText()); complete(); });
CloseWebSocketFrame frame = (CloseWebSocketFrame) msg; assertEquals(status, frame.statusCode()); assertEquals(reason, frame.reasonText()); complete(); });
CloseWebSocketFrame closeFrame = new CloseWebSocketFrame(frame.statusCode(), frame.reasonText()); chctx.writeAndFlush(closeFrame).addListener(ChannelFutureListener.CLOSE); closeFrameSent = true;
@Override public void onClose(ChannelHandlerContext ctx, CloseWebSocketFrame frame) { System.out.println("DISCONNECTED:" + frame.reasonText()); }
CloseWebSocketFrame frame = (CloseWebSocketFrame) msg; assertEquals(status, frame.statusCode()); assertEquals(reason, frame.reasonText()); complete(); });
CloseWebSocketFrame frame = (CloseWebSocketFrame) msg; assertEquals(status, frame.statusCode()); assertEquals(reason, frame.reasonText()); complete(); });
public void handle(final Object msg) { ready(); if (msg instanceof TextWebSocketFrame) { onTextCallback.accept(((TextWebSocketFrame) msg).text()); } else if (msg instanceof BinaryWebSocketFrame) { onBinaryCallback.accept(((BinaryWebSocketFrame) msg).content().nioBuffer()); } else if (msg instanceof CloseWebSocketFrame) { CloseWebSocketFrame closeFrame = ((CloseWebSocketFrame) msg).retain(); int statusCode = closeFrame.statusCode(); onCloseCallback.accept(statusCode == -1 ? WebSocket.NORMAL.code() : statusCode, Optional.ofNullable(closeFrame.reasonText())); handshaker.close(ctx.channel(), closeFrame).addListener(CLOSE); } else if (msg instanceof Throwable) { onErrorCallback.accept((Throwable) msg); } }
private void notifyCloseMessage(CloseWebSocketFrame closeWebSocketFrame) throws ServerConnectorException { String reasonText = closeWebSocketFrame.reasonText(); int statusCode = closeWebSocketFrame.statusCode(); ctx.channel().close(); channelSession.setIsOpen(false); WebSocketMessageImpl webSocketCloseMessage = new WebSocketCloseMessageImpl(statusCode, reasonText); webSocketCloseMessage = setupCommonProperties(webSocketCloseMessage); connectorFuture.notifyWSListener((WebSocketCloseMessage) webSocketCloseMessage); }
private void notifyCloseMessage(CloseWebSocketFrame closeWebSocketFrame, ChannelHandlerContext ctx) throws ServerConnectorException { String reasonText = closeWebSocketFrame.reasonText(); int statusCode = closeWebSocketFrame.statusCode(); ctx.channel().close(); if (channelSession == null) { throw new ServerConnectorException("Cannot find initialized channel session"); } channelSession.setIsOpen(false); WebSocketMessageImpl webSocketCloseMessage = new WebSocketCloseMessageImpl(statusCode, reasonText); webSocketCloseMessage = setupCommonProperties(webSocketCloseMessage, ctx); connectorListener.onMessage((WebSocketCloseMessage) webSocketCloseMessage); }
CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame; log.info("{} Received close frame from server. Will close client! Reason: {}", label, closeFrame.reasonText()); } else { log.warn("{} Received frame of type {}. Will be ignored", label,
/** * Handles web socket frame. * * @param ctx * {@link ChannelHandlerContext} * @param frame * {@link WebSocketFrame} */ private void handleWebSocketFrame(final ChannelHandlerContext ctx, final WebSocketFrame frame) throws IOException { if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain()); String streamName = Notificator.createStreamNameFromUri(((CloseWebSocketFrame) frame).reasonText()); ListenerAdapter listener = Notificator.getListenerFor(streamName); if (listener != null) { listener.removeSubscriber(ctx.channel()); logger.debug("Subscriber successfully registered."); } Notificator.removeListenerIfNoSubscriberExists(listener); return; } else if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } }
private void notifyCloseMessage(CloseWebSocketFrame closeWebSocketFrame) throws WebSocketConnectorException { String reasonText = closeWebSocketFrame.reasonText(); int statusCode = closeWebSocketFrame.statusCode(); if (statusCode == -1) { statusCode = 1005; } // closePromise == null means that WebSocketConnection has not yet initiated a connection closure. if (closePromise == null) { DefaultWebSocketMessage webSocketCloseMessage = new DefaultWebSocketCloseMessage(statusCode, reasonText); setupCommonProperties(webSocketCloseMessage); connectorFuture.notifyWebSocketListener((WebSocketCloseMessage) webSocketCloseMessage); } else { if (webSocketConnection.getCloseInitiatedStatusCode() != statusCode) { String errMsg = String.format( "Expected status code %d but found %d in echoed close frame from remote endpoint", webSocketConnection.getCloseInitiatedStatusCode(), statusCode); closePromise.setFailure(new IllegalStateException(errMsg)); return; } closePromise.setSuccess(); } closeWebSocketFrame.release(); }
Channels.setDiscard(channel); CloseWebSocketFrame closeFrame = CloseWebSocketFrame.class.cast(frame); webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText()); } else { ByteBuf buf = frame.content();
Channels.setDiscard(channel); CloseWebSocketFrame closeFrame = CloseWebSocketFrame.class.cast(frame); webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText()); } else { ByteBuf buf = frame.content();