use of io.netty.handler.codec.http.websocketx.PongWebSocketFrame in project async-http-client by AsyncHttpClient.
the class NettyWebSocket method sendPong.
@Override
public WebSocket sendPong(final byte[] payload, final WebSocketWriteCompleteListener listener) {
final ChannelPromise channelPromise = channel.newPromise();
channelPromise.addListener(listener);
channel.writeAndFlush(new PongWebSocketFrame(wrappedBuffer(payload)), channelPromise);
return this;
}
use of io.netty.handler.codec.http.websocketx.PongWebSocketFrame in project netty by netty.
the class WebSocketClientHandler method channelRead0.
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel ch = ctx.channel();
if (!handshaker.isHandshakeComplete()) {
handshaker.finishHandshake(ch, (FullHttpResponse) msg);
System.out.println("WebSocket Client connected!");
handshakeFuture.setSuccess();
return;
}
if (msg instanceof FullHttpResponse) {
FullHttpResponse response = (FullHttpResponse) msg;
throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');
}
WebSocketFrame frame = (WebSocketFrame) msg;
if (frame instanceof TextWebSocketFrame) {
TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
System.out.println("WebSocket Client received message: " + textFrame.text());
} else if (frame instanceof PongWebSocketFrame) {
System.out.println("WebSocket Client received pong");
} else if (frame instanceof CloseWebSocketFrame) {
System.out.println("WebSocket Client received closing");
ch.close();
}
}
use of io.netty.handler.codec.http.websocketx.PongWebSocketFrame in project async-http-client by AsyncHttpClient.
the class NettyWebSocket method handleFrame.
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) {
onPing((PingWebSocketFrame) frame);
} else if (frame instanceof PongWebSocketFrame) {
onPong((PongWebSocketFrame) frame);
}
}
Aggregations