@Test public void testServerWebsocketPingExceeds125Bytes() { testServerWebsocketPingPongCheck(255, ws -> { try { ws.writePing(Buffer.buffer(randomAlphaString(126))); } catch(Throwable expected) { assertEquals("Ping cannot exceed maxWebSocketFrameSize or 125 bytes", expected.getMessage()); ws.close(); testComplete(); } }); }
@Test public void testServerWebsocketPingExceedsMaxFrameSize() { testServerWebsocketPingPongCheck(100, ws -> { try { ws.writePing(Buffer.buffer(randomAlphaString(101))); } catch(Throwable expected) { assertEquals("Ping cannot exceed maxWebSocketFrameSize or 125 bytes", expected.getMessage()); ws.close(); testComplete(); } }); }
@Test public void testServerWebsocketPingPong() { server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST)); server.websocketHandler(ws -> { ws.pongHandler(buff -> { assertEquals("ping", buff.toString()); testComplete(); }); ws.writePing(Buffer.buffer("ping")); }).listen(onSuccess(v -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> {}); })); await(); }
@Test public void testServerWebsocketPingExceeds125Bytes() { testServerWebsocketPingPongCheck(255, ws -> { try { ws.writePing(Buffer.buffer(randomAlphaString(126))); } catch(Throwable expected) { assertEquals("Ping cannot exceed maxWebSocketFrameSize or 125 bytes", expected.getMessage()); ws.close(); testComplete(); } }); }
@Test public void testServerWebsocketPingExceedsMaxFrameSize() { testServerWebsocketPingPongCheck(100, ws -> { try { ws.writePing(Buffer.buffer(randomAlphaString(101))); } catch(Throwable expected) { assertEquals("Ping cannot exceed maxWebSocketFrameSize or 125 bytes", expected.getMessage()); ws.close(); testComplete(); } }); }
@Test public void testServerWebsocketPingPong() { server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST)); server.websocketHandler(ws -> { ws.pongHandler(buff -> { assertEquals("ping", buff.toString()); testComplete(); }); ws.writePing(Buffer.buffer("ping")); }).listen(onSuccess(v -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> {}); })); await(); }
/** * Writes a ping to the connection. This will be written in a single frame. Ping frames may be at most 125 bytes (octets). * <p> * This method should not be used to write application data and should only be used for implementing a keep alive or * to ensure the client is still responsive, see RFC 6455 Section 5.5.2. * <p> * There is no pingHandler because RFC 6455 section 5.5.2 clearly states that the only response to a ping is a pong * with identical contents. * @param data the data to write, may be at most 125 bytes * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.WebSocketBase writePing(io.vertx.rxjava.core.buffer.Buffer data) { delegate.writePing(data.getDelegate()); return this; }
/** * Writes a ping to the connection. This will be written in a single frame. Ping frames may be at most 125 bytes (octets). * <p> * This method should not be used to write application data and should only be used for implementing a keep alive or * to ensure the client is still responsive, see RFC 6455 Section 5.5.2. * <p> * There is no pingHandler because RFC 6455 section 5.5.2 clearly states that the only response to a ping is a pong * with identical contents. * @param data the data to write, may be at most 125 bytes * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.core.http.WebSocketBase writePing(io.vertx.rxjava.core.buffer.Buffer data) { delegate.writePing(data.getDelegate()); return this; }