@Test public void testClientWebsocketPingPong() { server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST)); server.websocketHandler(ws -> { }).listen(onSuccess(v -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.pongHandler( pong -> { assertEquals("ping", pong.toString()); testComplete(); }); ws.writePing(Buffer.buffer("ping")); }); })); await(); }
@Test public void testClientWebsocketPingPong() { server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST)); server.websocketHandler(ws -> { }).listen(onSuccess(v -> { client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> { ws.pongHandler( pong -> { assertEquals("ping", pong.toString()); testComplete(); }); ws.writePing(Buffer.buffer("ping")); }); })); 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; }