use of io.netty.handler.codec.http.websocketx.PingWebSocketFrame in project netty by netty.
the class WebSocketExtensionFilterTest method testAlwaysSkip.
@Test
public void testAlwaysSkip() {
WebSocketExtensionFilter neverSkip = WebSocketExtensionFilter.ALWAYS_SKIP;
BinaryWebSocketFrame binaryFrame = new BinaryWebSocketFrame();
assertTrue(neverSkip.mustSkip(binaryFrame));
assertTrue(binaryFrame.release());
TextWebSocketFrame textFrame = new TextWebSocketFrame();
assertTrue(neverSkip.mustSkip(textFrame));
assertTrue(textFrame.release());
PingWebSocketFrame pingFrame = new PingWebSocketFrame();
assertTrue(neverSkip.mustSkip(pingFrame));
assertTrue(pingFrame.release());
PongWebSocketFrame pongFrame = new PongWebSocketFrame();
assertTrue(neverSkip.mustSkip(pongFrame));
assertTrue(pongFrame.release());
CloseWebSocketFrame closeFrame = new CloseWebSocketFrame();
assertTrue(neverSkip.mustSkip(closeFrame));
assertTrue(closeFrame.release());
ContinuationWebSocketFrame continuationFrame = new ContinuationWebSocketFrame();
assertTrue(neverSkip.mustSkip(continuationFrame));
assertTrue(continuationFrame.release());
}
use of io.netty.handler.codec.http.websocketx.PingWebSocketFrame in project netty by netty.
the class WebSocketExtensionFilterTest method testNeverSkip.
@Test
public void testNeverSkip() {
WebSocketExtensionFilter neverSkip = WebSocketExtensionFilter.NEVER_SKIP;
BinaryWebSocketFrame binaryFrame = new BinaryWebSocketFrame();
assertFalse(neverSkip.mustSkip(binaryFrame));
assertTrue(binaryFrame.release());
TextWebSocketFrame textFrame = new TextWebSocketFrame();
assertFalse(neverSkip.mustSkip(textFrame));
assertTrue(textFrame.release());
PingWebSocketFrame pingFrame = new PingWebSocketFrame();
assertFalse(neverSkip.mustSkip(pingFrame));
assertTrue(pingFrame.release());
PongWebSocketFrame pongFrame = new PongWebSocketFrame();
assertFalse(neverSkip.mustSkip(pongFrame));
assertTrue(pongFrame.release());
CloseWebSocketFrame closeFrame = new CloseWebSocketFrame();
assertFalse(neverSkip.mustSkip(closeFrame));
assertTrue(closeFrame.release());
ContinuationWebSocketFrame continuationFrame = new ContinuationWebSocketFrame();
assertFalse(neverSkip.mustSkip(continuationFrame));
assertTrue(continuationFrame.release());
}
use of io.netty.handler.codec.http.websocketx.PingWebSocketFrame in project autobahn-java by crossbario.
the class NettyWebSocketClientHandler method channelRead0.
@Override
public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel ch = ctx.channel();
if (!mHandshaker.isHandshakeComplete()) {
FullHttpResponse response = (FullHttpResponse) msg;
String negotiatedSerializer = response.headers().get("Sec-WebSocket-Protocol");
LOGGER.d(String.format("Negotiated serializer=%s", negotiatedSerializer));
ISerializer serializer = initializeSerializer(negotiatedSerializer);
mHandshaker.finishHandshake(ch, response);
mHandshakeFuture.setSuccess();
mTransportHandler.onConnect(mTransport, serializer);
} else if (msg instanceof FullHttpResponse) {
FullHttpResponse response = (FullHttpResponse) msg;
throw new IllegalStateException("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" + response.content().toString(CharsetUtil.UTF_8) + ')');
} else if (msg instanceof BinaryWebSocketFrame) {
BinaryWebSocketFrame binaryWebSocketFrame = (BinaryWebSocketFrame) msg;
byte[] payload = new byte[binaryWebSocketFrame.content().readableBytes()];
LOGGER.v(String.format("Received binary frame, content length=%s", payload.length));
binaryWebSocketFrame.content().readBytes(payload);
mTransportHandler.onMessage(payload, true);
} else if (msg instanceof TextWebSocketFrame) {
TextWebSocketFrame textWebSocketFrame = (TextWebSocketFrame) msg;
byte[] payload = new byte[textWebSocketFrame.content().readableBytes()];
LOGGER.v(String.format("Received Text frame, content length=%s", payload.length));
textWebSocketFrame.content().readBytes(payload);
mTransportHandler.onMessage(payload, false);
} else if (msg instanceof PingWebSocketFrame) {
PingWebSocketFrame pingWebSocketFrame = (PingWebSocketFrame) msg;
ctx.writeAndFlush(new PongWebSocketFrame(pingWebSocketFrame.content().retain()));
} else if (msg instanceof PongWebSocketFrame) {
// Not really doing anything here.
LOGGER.v("WebSocket Client received pong.");
} else if (msg instanceof CloseWebSocketFrame) {
CloseWebSocketFrame closeWebSocketFrame = (CloseWebSocketFrame) msg;
LOGGER.d(String.format("Received Close frame, code=%s, reason=%s", closeWebSocketFrame.statusCode(), closeWebSocketFrame.reasonText()));
close(ctx, closeWebSocketFrame.statusCode() == 1000, new CloseDetails(CloseDetails.REASON_DEFAULT, null));
}
}
use of io.netty.handler.codec.http.websocketx.PingWebSocketFrame in project reactor-netty by reactor.
the class WebsocketTest method testIssue663_3.
@Test
void testIssue663_3() throws Exception {
AtomicBoolean incomingData = new AtomicBoolean();
CountDownLatch latch = new CountDownLatch(1);
disposableServer = createServer().handle((req, resp) -> resp.sendWebsocket((i, o) -> i.receiveFrames().then())).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> out.sendObject(Flux.just(new PingWebSocketFrame(), new CloseWebSocketFrame()).delayElements(Duration.ofMillis(100))).then(in.receiveFrames().doOnNext(f -> {
if (f instanceof PongWebSocketFrame) {
incomingData.set(true);
}
}).doOnComplete(latch::countDown).then())).subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(incomingData.get()).isTrue();
}
use of io.netty.handler.codec.http.websocketx.PingWebSocketFrame in project reactor-netty by reactor.
the class WebsocketTest method testIssue663_4.
@Test
void testIssue663_4() throws Exception {
AtomicBoolean incomingData = new AtomicBoolean();
CountDownLatch latch = new CountDownLatch(1);
disposableServer = createServer().handle((req, resp) -> resp.sendWebsocket((i, o) -> i.receiveFrames().then(), WebsocketServerSpec.builder().handlePing(true).build())).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> out.sendObject(Flux.just(new PingWebSocketFrame(), new CloseWebSocketFrame()).delayElements(Duration.ofMillis(100))).then(in.receiveFrames().doOnNext(f -> incomingData.set(true)).doOnComplete(latch::countDown).then())).subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(incomingData.get()).isFalse();
}
Aggregations