@Override public Future<Void> sendPingFrame() { return channel.writeAndFlush(new PingWebSocketFrame()); }
@Override public Future<Void> sendPingFrame(ByteBuf payload) { return channel.writeAndFlush(new PingWebSocketFrame(payload)); }
@Override public ChannelFuture sendPing(ChannelHandlerContext ctx) { return ctx.channel().writeAndFlush(new PingWebSocketFrame()); }
@Override public ChannelFuture sendPing(ChannelHandlerContext ctx) { return ctx.channel().writeAndFlush(new PingWebSocketFrame()); }
@Override public PingWebSocketFrame replace(ByteBuf content) { return new PingWebSocketFrame(isFinalFragment(), rsv(), content); }
@Override protected void encode(ChannelHandlerContext ctx, WebSocketConvertHandler.MyWebSocketFrame msg, List<Object> out) throws Exception { ByteBuf payload = msg.getData().duplicate().retain(); switch (msg.getType()) { case BINARY: out.add(new BinaryWebSocketFrame(payload)); break; case TEXT: out.add(new TextWebSocketFrame(payload)); break; case CLOSE: out.add(new CloseWebSocketFrame(true, 0, payload)); break; case CONTINUATION: out.add(new ContinuationWebSocketFrame(payload)); break; case PONG: out.add(new PongWebSocketFrame(payload)); break; case PING: out.add(new PingWebSocketFrame(payload)); break; default: throw new IllegalStateException( "Unsupported websocket msg " + msg);} }
WebSocketFrame encodeFrame(WebSocketFrameImpl frame) { ByteBuf buf = frame.getBinaryData(); if (buf != Unpooled.EMPTY_BUFFER) { buf = safeBuffer(buf, chctx.alloc()); } switch (frame.type()) { case BINARY: return new BinaryWebSocketFrame(frame.isFinal(), 0, buf); case TEXT: return new TextWebSocketFrame(frame.isFinal(), 0, buf); case CLOSE: return new CloseWebSocketFrame(true, 0, buf); case CONTINUATION: return new ContinuationWebSocketFrame(frame.isFinal(), 0, buf); case PONG: return new PongWebSocketFrame(buf); case PING: return new PingWebSocketFrame(buf); default: throw new IllegalStateException("Unsupported websocket msg " + frame); } }
protected WebSocketFrame toFrame(WebSocketMessage message) { ByteBuf byteBuf = NettyDataBufferFactory.toByteBuf(message.getPayload()); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { return new TextWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { return new BinaryWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { return new PingWebSocketFrame(byteBuf); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { return new PongWebSocketFrame(byteBuf); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } }
out.add(new PingWebSocketFrame(frameFinalFlag, frameRsv, payloadBuffer)); payloadBuffer = null; return;
@Override public Object createIdleDetectionMessage() { return new PingWebSocketFrame(); }
@Override public Object createKeepAliveMessage() { return new PingWebSocketFrame(); }
WebSocketFrame encodeFrame(WebSocketFrameImpl frame) { ByteBuf buf = frame.getBinaryData(); if (buf != Unpooled.EMPTY_BUFFER) { buf = safeBuffer(buf, chctx.alloc()); } switch (frame.type()) { case BINARY: return new BinaryWebSocketFrame(frame.isFinal(), 0, buf); case TEXT: return new TextWebSocketFrame(frame.isFinal(), 0, buf); case CLOSE: return new CloseWebSocketFrame(true, 0, buf); case CONTINUATION: return new ContinuationWebSocketFrame(frame.isFinal(), 0, buf); case PONG: return new PongWebSocketFrame(buf); case PING: return new PingWebSocketFrame(buf); default: throw new IllegalStateException("Unsupported websocket msg " + frame); } }
@Override public WebSocket sendPing(byte[] payload) { channel.writeAndFlush(new PingWebSocketFrame(wrappedBuffer(payload))); return this; }
/** * Send a WebSocket Ping * * @param payload the bytes to send * @return this */ public WebSocket sendPing(byte[] payload) { channel.writeAndFlush(new PingWebSocketFrame(Unpooled.wrappedBuffer(payload))); return this; }
@Override public ChannelFuture sendPing(ChannelHandlerContext ctx) { return ctx.channel().writeAndFlush(new PingWebSocketFrame()); } },
/** * Writes {@link PingWebSocketFrame} * through the {@link ChannelPipeline} and request to actual * {@link Channel#flush()} to flush all pending data to the actual transport. */ public void ping() { clientChannel.writeAndFlush(new PingWebSocketFrame(Unpooled .copiedBuffer(new byte[] { 1, 2, 3, 4, 5, 6 }))); }
@Override public WebSocket sendPing(byte[] payload) { channel.writeAndFlush(new PingWebSocketFrame(wrappedBuffer(payload))); return this; }
public WsClientHandler(ChannelHandlerContext ctx, int pingRate) { this.ctx = ctx; this.ping = this.ctx.executor().scheduleAtFixedRate(() -> { LOG.trace("Sending ping on channel {}", ctx.channel()); ctx.writeAndFlush(new PingWebSocketFrame()); }, pingRate, pingRate, TimeUnit.SECONDS); }
@Override public PingWebSocketFrame replace(ByteBuf content) { return new PingWebSocketFrame(isFinalFragment(), rsv(), content); }
/** * Send a ping message to the server. * @param buf content of the ping message to be sent. */ public void sendPing(ByteBuffer buf) throws IOException, InterruptedException { if (channel == null) { logger.error("Channel is null. Cannot send text."); throw new IllegalArgumentException("Cannot find the channel to write"); } channel.writeAndFlush(new PingWebSocketFrame(Unpooled.wrappedBuffer(buf))).sync(); }