Example usage for io.netty.handler.codec.http.websocketx ContinuationWebSocketFrame ContinuationWebSocketFrame

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

Introduction

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

Prototype

public ContinuationWebSocketFrame(ByteBuf binaryData) 

Source Link

Document

Creates a new continuation frame with the specified binary data.

Usage

From source file:io.jsync.http.impl.AsyncHttpHandler.java

License:Open Source License

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    if (msg instanceof WebSocketFrameInternal) {
        WebSocketFrameInternal frame = (WebSocketFrameInternal) msg;
        ByteBuf buf = frame.getBinaryData();
        if (buf != Unpooled.EMPTY_BUFFER) {
            buf = safeBuffer(buf, ctx.alloc());
        }/*from  ww  w .  ja v  a2s  .co m*/
        switch (frame.type()) {
        case BINARY:
            msg = new BinaryWebSocketFrame(buf);
            break;
        case TEXT:
            msg = new TextWebSocketFrame(buf);
            break;
        case CLOSE:
            msg = new CloseWebSocketFrame(true, 0, buf);
            break;
        case CONTINUATION:
            msg = new ContinuationWebSocketFrame(buf);
            break;
        case PONG:
            msg = new PongWebSocketFrame(buf);
            break;
        case PING:
            msg = new PingWebSocketFrame(buf);
            break;
        default:
            throw new IllegalStateException("Unsupported websocket msg " + msg);
        }
    }
    ctx.write(msg, promise);
}

From source file:org.ballerinalang.test.util.websocket.client.WebSocketTestClient.java

License:Open Source License

/**
 * Send corrupted frame to the server.//from  w w w. j  ava 2s  . com
 *
 * @throws InterruptedException if connection is interrupted while sending the message.
 */
public void sendCorruptedFrame() throws InterruptedException {
    if (channel == null) {
        logger.error("Channel is null. Cannot send text.");
        throw new IllegalArgumentException("Cannot find the channel to write");
    }
    channel.writeAndFlush(new ContinuationWebSocketFrame(Unpooled.wrappedBuffer(new byte[] { 1, 2, 3, 4 })))
            .sync();
}