ctx.writeAndFlush(new PongWebSocketFrame()); } finally { ((PingWebSocketFrame) msg).release();
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // Discard messages when we are not reading if (readState != ReadState.Reading) { ReferenceCountUtil.release(msg); return; } // We might receive http requests here when the whe clients sends something after the upgrade // request but we have not fully sent out the response and the http codec is still installed. // However that would be an error. if (msg instanceof FullHttpRequest) { ((FullHttpRequest) msg).release(); WampServerWebsocketHandler.sendBadRequestAndClose(ctx, null); return; } if (msg instanceof PingWebSocketFrame) { // Respond to Pings with Pongs try { ctx.writeAndFlush(new PongWebSocketFrame()); } finally { ((PingWebSocketFrame) msg).release(); } } else if (msg instanceof CloseWebSocketFrame) { // Echo the close and close the connection readState = ReadState.Closed; ctx.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); } else { ctx.fireChannelRead(msg); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // Discard messages when we are not reading if (readState != ReadState.Reading) { ReferenceCountUtil.release(msg); return; } // We might receive http requests here when the whe clients sends something after the upgrade // request but we have not fully sent out the response and the http codec is still installed. // However that would be an error. if (msg instanceof FullHttpRequest) { ((FullHttpRequest) msg).release(); WampServerWebsocketHandler.sendBadRequestAndClose(ctx, null); return; } if (msg instanceof PingWebSocketFrame) { // Respond to Pings with Pongs try { ctx.writeAndFlush(new PongWebSocketFrame()); } finally { ((PingWebSocketFrame) msg).release(); } } else if (msg instanceof CloseWebSocketFrame) { // Echo the close and close the connection readState = ReadState.Closed; ctx.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); } else { ctx.fireChannelRead(msg); } }