@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); }
public io.vertx.rxjava.core.http.WebSocket writeTextMessage(String text) { delegate.writeTextMessage(text); return this; }
public io.vertx.rxjava.core.http.WebSocket writeTextMessage(String text) { delegate.writeTextMessage(text); return this; }
client.websocket("/test/400/8ne8e94a/websocket", ws -> ws.handler(msg -> { clientReceived.addAndGet(msg.length()); ws.writeTextMessage("\"hello\""); if (shallStop.getAsBoolean()) { ws.handler(null);
@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); }
private void subscribeTo(String channel) { final ListenerSubscribeMessage subscribeMessage = new ListenerSubscribeMessage(this.UID, channel); String json; try { json = objectMapper.writeValueAsString(subscribeMessage); } catch (JsonProcessingException e) { throw new RuntimeException(e.getCause()); } this.webSocket.writeTextMessage(json); }
private void handleSocketSend(final Message<JsonObject> msg) { if(socket != null && socketOpen) { JsonObject payload = msg.body(); for(final Extension extension : catnip.extensionManager().extensions()) { for(final CatnipHook hook : extension.hooks()) { payload = hook.rawGatewaySendHook(payload); } } socket.writeTextMessage(payload.encode()); } }
client.websocket("/test/400/8ne8e94a/websocket", ws -> ws.handler(msg -> { clientReceived.addAndGet(msg.length()); ws.writeTextMessage("\"hello\""); if (shallStop.getAsBoolean()) { ws.handler(null);
private void wsRequest(HttpClient httpClient, TestContext ctx) { Async async = ctx.async(); httpClient.websocket(9195, "127.0.0.1", "", ws -> { ws.handler(event -> { async.complete(); ws.close(); }); ws.writeTextMessage(CLIENT_REQUEST); }, ctx::fail); async.await(); } }