use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project undertow by undertow-io.
the class JsrWebSocketServer07Test method testBinaryWithByteBuffer.
@org.junit.Test
public void testBinaryWithByteBuffer() throws Exception {
final byte[] payload = "payload".getBytes();
final AtomicReference<Throwable> cause = new AtomicReference<>();
final AtomicBoolean connected = new AtomicBoolean(false);
final FutureResult latch = new FutureResult();
class TestEndPoint extends Endpoint {
@Override
public void onOpen(final Session session, EndpointConfig config) {
connected.set(true);
session.addMessageHandler(new MessageHandler.Whole<ByteBuffer>() {
@Override
public void onMessage(ByteBuffer message) {
ByteBuffer buf = ByteBuffer.allocate(message.remaining());
buf.put(message);
buf.flip();
session.getAsyncRemote().sendBinary(buf);
}
});
}
}
ServerWebSocketContainer builder = new ServerWebSocketContainer(TestClassIntrospector.INSTANCE, DefaultServer.getWorker(), DefaultServer.getBufferPool(), Collections.EMPTY_LIST, false, false);
builder.addEndpoint(ServerEndpointConfig.Builder.create(TestEndPoint.class, "/").configurator(new InstanceConfigurator(new TestEndPoint())).build());
deployServlet(builder);
WebSocketTestClient client = new WebSocketTestClient(getVersion(), new URI("ws://" + NetworkUtils.formatPossibleIpv6Address(DefaultServer.getHostAddress("default")) + ":" + DefaultServer.getHostPort("default") + "/"));
client.connect();
client.send(new BinaryWebSocketFrame(Unpooled.wrappedBuffer(payload)), new FrameChecker(BinaryWebSocketFrame.class, payload, latch));
latch.getIoFuture().get();
Assert.assertNull(cause.get());
client.destroy();
}
use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project async-http-client by AsyncHttpClient.
the class NettyWebSocket method stream.
@Override
public WebSocket stream(final byte[] fragment, final boolean last, final WebSocketWriteCompleteListener listener) {
final ChannelPromise channelPromise = channel.newPromise();
channelPromise.addListener(listener);
channel.writeAndFlush(new BinaryWebSocketFrame(last, 0, wrappedBuffer(fragment)), channelPromise);
return this;
}
use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame 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