@Test public void testCloseStatusCodeFromClient() throws InterruptedException { CountDownLatch latch = new CountDownLatch(2); client = vertx.createHttpClient(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)) .websocketHandler(socket -> { socket.closeHandler(a -> { latch.countDown(); }); socket.frameHandler(frame -> { assertEquals(1000, frame.binaryData().getByteBuf().getShort(0)); assertEquals(1000, frame.closeStatusCode()); assertNull(frame.closeReason()); latch.countDown(); }); }) .listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.close(); }); }); awaitLatch(latch); }
@Test public void testCloseCustomPayloadFromClient() throws InterruptedException { final String REASON = "I'm moving away!"; final short STATUS_CODE = (short)1001; CountDownLatch latch = new CountDownLatch(2); client = vertx.createHttpClient(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)) .websocketHandler(socket -> { socket.closeHandler(a -> { latch.countDown(); }); socket.frameHandler(frame -> { assertEquals(REASON, frame.binaryData().getByteBuf().readerIndex(2).toString(StandardCharsets.UTF_8)); assertEquals(STATUS_CODE, frame.binaryData().getByteBuf().getShort(0)); assertEquals(REASON, frame.closeReason()); assertEquals(STATUS_CODE, frame.closeStatusCode()); latch.countDown(); }); }) .listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.close(STATUS_CODE, REASON); }); }); awaitLatch(latch); }
@Test public void testCloseFrame() throws InterruptedException { CountDownLatch latch = new CountDownLatch(3); client = vertx.createHttpClient(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)) .websocketHandler(socket -> { socket.closeHandler(a -> { latch.countDown(); }); socket.frameHandler(frame -> { if (frame.isText()) { assertIllegalStateException(frame::closeStatusCode); } else { assertEquals(frame.closeReason(), "It was a good talk"); assertEquals(frame.closeStatusCode(), 1001); } latch.countDown(); }); }) .listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.writeTextMessage("Hello"); ws.close((short)1001, "It was a good talk"); }); }); awaitLatch(latch); }
assertEquals("upgrade", ws.headers().get("Connection")); AtomicInteger count = new AtomicInteger(); ws.frameHandler(frame -> { if (frame.isClose()) { testComplete();
ws.frameHandler(frame -> { if (frame.isClose()) { complete();
public io.vertx.rxjava.core.http.ServerWebSocket frameHandler(Handler<io.vertx.rxjava.core.http.WebSocketFrame> handler) { delegate.frameHandler(new Handler<io.vertx.core.http.WebSocketFrame>() { public void handle(io.vertx.core.http.WebSocketFrame event) { handler.handle(io.vertx.rxjava.core.http.WebSocketFrame.newInstance(event)); } }); return this; }
public io.vertx.rxjava.core.http.ServerWebSocket frameHandler(Handler<io.vertx.rxjava.core.http.WebSocketFrame> handler) { delegate.frameHandler(new Handler<io.vertx.core.http.WebSocketFrame>() { public void handle(io.vertx.core.http.WebSocketFrame event) { handler.handle(io.vertx.rxjava.core.http.WebSocketFrame.newInstance(event)); } }); return this; }
@Test public void testCloseFrame() throws InterruptedException { CountDownLatch latch = new CountDownLatch(3); client = vertx.createHttpClient(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)) .websocketHandler(socket -> { socket.closeHandler(a -> { latch.countDown(); }); socket.frameHandler(frame -> { if (frame.isText()) { assertIllegalStateException(frame::closeStatusCode); } else { assertEquals(frame.closeReason(), "It was a good talk"); assertEquals(frame.closeStatusCode(), 1001); } latch.countDown(); }); }) .listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.writeTextMessage("Hello"); ws.close((short)1001, "It was a good talk"); }); }); awaitLatch(latch); }
@Test public void testCloseStatusCodeFromClient() throws InterruptedException { CountDownLatch latch = new CountDownLatch(2); client = vertx.createHttpClient(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)) .websocketHandler(socket -> { socket.closeHandler(a -> { latch.countDown(); }); socket.frameHandler(frame -> { assertEquals(1000, frame.binaryData().getByteBuf().getShort(0)); assertEquals(1000, frame.closeStatusCode()); assertNull(frame.closeReason()); latch.countDown(); }); }) .listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.close(); }); }); awaitLatch(latch); }
@Test public void testCloseCustomPayloadFromClient() throws InterruptedException { final String REASON = "I'm moving away!"; final short STATUS_CODE = (short)1001; CountDownLatch latch = new CountDownLatch(2); client = vertx.createHttpClient(); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)) .websocketHandler(socket -> { socket.closeHandler(a -> { latch.countDown(); }); socket.frameHandler(frame -> { assertEquals(REASON, frame.binaryData().getByteBuf().readerIndex(2).toString(StandardCharsets.UTF_8)); assertEquals(STATUS_CODE, frame.binaryData().getByteBuf().getShort(0)); assertEquals(REASON, frame.closeReason()); assertEquals(STATUS_CODE, frame.closeStatusCode()); latch.countDown(); }); }) .listen(ar -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.close(STATUS_CODE, REASON); }); }); awaitLatch(latch); }
assertEquals("upgrade", ws.headers().get("Connection")); AtomicInteger count = new AtomicInteger(); ws.frameHandler(frame -> { if (frame.isClose()) { testComplete();
vertxServerWebSocket.frameHandler(event -> {
ws.frameHandler(frame -> { if (frame.isClose()) { complete();
private void manageWebSocket(String announceAddress, ServerWebSocket socket) { socket .exceptionHandler(Throwable::printStackTrace) .frameHandler(frame -> { .frameHandler(innerframe -> { vertx.eventBus().send(address, new JsonObject().put("event", "message")
break; case "/record": socket.frameHandler(frame -> { buffer.appendString(frame.textData()); if (!frame.isFinal()) {
vertxServerWebSocket.frameHandler(event -> {