Search in sources :

Example 1 with WebSocketFrame

use of io.vertx.core.http.WebSocketFrame in project vert.x by eclipse.

the class WebSocketImplBase method writePartialMessage.

/**
   * Splits the provided buffer into multiple frames (which do not exceed the maximum web socket frame size)
   * and writes them in order to the socket.
   */
private void writePartialMessage(FrameType frameType, Buffer data, int offset) {
    int end = offset + maxWebSocketFrameSize;
    boolean isFinal;
    if (end >= data.length()) {
        end = data.length();
        isFinal = true;
    } else {
        isFinal = false;
    }
    Buffer slice = data.slice(offset, end);
    WebSocketFrame frame;
    if (offset == 0 || !supportsContinuation) {
        frame = new WebSocketFrameImpl(frameType, slice.getByteBuf(), isFinal);
    } else {
        frame = WebSocketFrame.continuationFrame(slice, isFinal);
    }
    writeFrame(frame);
    int newOffset = offset + maxWebSocketFrameSize;
    if (!isFinal) {
        writePartialMessage(frameType, data, newOffset);
    }
}
Also used : Buffer(io.vertx.core.buffer.Buffer) WebSocketFrameImpl(io.vertx.core.http.impl.ws.WebSocketFrameImpl) WebSocketFrame(io.vertx.core.http.WebSocketFrame)

Example 2 with WebSocketFrame

use of io.vertx.core.http.WebSocketFrame in project vert.x by eclipse.

the class WebSocketImplBase method writeBinaryFrameInternal.

private void writeBinaryFrameInternal(Buffer data) {
    ByteBuf buf = data.getByteBuf();
    WebSocketFrame frame = new WebSocketFrameImpl(FrameType.BINARY, buf);
    writeFrame(frame);
}
Also used : WebSocketFrameImpl(io.vertx.core.http.impl.ws.WebSocketFrameImpl) WebSocketFrame(io.vertx.core.http.WebSocketFrame) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with WebSocketFrame

use of io.vertx.core.http.WebSocketFrame in project vert.x by eclipse.

the class WebSocketImplBase method writeTextFrameInternal.

private void writeTextFrameInternal(String str) {
    WebSocketFrame frame = new WebSocketFrameImpl(str);
    writeFrame(frame);
}
Also used : WebSocketFrameImpl(io.vertx.core.http.impl.ws.WebSocketFrameImpl) WebSocketFrame(io.vertx.core.http.WebSocketFrame)

Aggregations

WebSocketFrame (io.vertx.core.http.WebSocketFrame)3 WebSocketFrameImpl (io.vertx.core.http.impl.ws.WebSocketFrameImpl)3 ByteBuf (io.netty.buffer.ByteBuf)1 Buffer (io.vertx.core.buffer.Buffer)1