Search in sources :

Example 1 with PongWebSocketFrame

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;
}
Also used : PongWebSocketFrame(io.netty.handler.codec.http.websocketx.PongWebSocketFrame) ChannelPromise(io.netty.channel.ChannelPromise)

Example 2 with PongWebSocketFrame

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();
    }
}
Also used : CloseWebSocketFrame(io.netty.handler.codec.http.websocketx.CloseWebSocketFrame) PongWebSocketFrame(io.netty.handler.codec.http.websocketx.PongWebSocketFrame) Channel(io.netty.channel.Channel) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) WebSocketFrame(io.netty.handler.codec.http.websocketx.WebSocketFrame) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) PongWebSocketFrame(io.netty.handler.codec.http.websocketx.PongWebSocketFrame) CloseWebSocketFrame(io.netty.handler.codec.http.websocketx.CloseWebSocketFrame)

Example 3 with PongWebSocketFrame

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);
    }
}
Also used : CloseWebSocketFrame(io.netty.handler.codec.http.websocketx.CloseWebSocketFrame) PongWebSocketFrame(io.netty.handler.codec.http.websocketx.PongWebSocketFrame) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) PingWebSocketFrame(io.netty.handler.codec.http.websocketx.PingWebSocketFrame)

Aggregations

PongWebSocketFrame (io.netty.handler.codec.http.websocketx.PongWebSocketFrame)3 CloseWebSocketFrame (io.netty.handler.codec.http.websocketx.CloseWebSocketFrame)2 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)2 Channel (io.netty.channel.Channel)1 ChannelPromise (io.netty.channel.ChannelPromise)1 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)1 BinaryWebSocketFrame (io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame)1 PingWebSocketFrame (io.netty.handler.codec.http.websocketx.PingWebSocketFrame)1 WebSocketFrame (io.netty.handler.codec.http.websocketx.WebSocketFrame)1