Example usage for io.netty.handler.codec.http.websocketx BinaryWebSocketFrame retain

List of usage examples for io.netty.handler.codec.http.websocketx BinaryWebSocketFrame retain

Introduction

In this page you can find the example usage for io.netty.handler.codec.http.websocketx BinaryWebSocketFrame retain.

Prototype

@Override
    public BinaryWebSocketFrame retain() 

Source Link

Usage

From source file:cc.blynk.integration.model.websocket.WebSocketClientHandler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    Channel ch = ctx.channel();//  ww  w .  jav a2  s.  c o m
    if (!handshaker.isHandshakeComplete()) {
        handshaker.finishHandshake(ch, (FullHttpResponse) msg);
        log.trace("WebSocket Client connected!");
        if (handshakeFuture != null) {
            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 BinaryWebSocketFrame) {
        BinaryWebSocketFrame binaryFrame = (BinaryWebSocketFrame) frame;
        log.trace("WebSocket Client received message: " + binaryFrame.content());
        ctx.fireChannelRead(binaryFrame.retain().content());
    } else if (frame instanceof CloseWebSocketFrame) {
        log.trace("WebSocket Client received closing");
        ch.close();
    }
}

From source file:com.barchart.netty.server.http.websocket.WebSocketFrameUnpacker.java

License:BSD License

@Override
protected void decode(final ChannelHandlerContext ctx, final BinaryWebSocketFrame msg, final List<Object> out)
        throws Exception {
    msg.retain();
    out.add(msg.content());// www  .  ja  v  a2  s . com
}