private void testValidSubProtocol(WebsocketVersion version) throws Exception { String path = "/some/path"; String clientSubProtocols = "clientproto,commonproto"; String serverSubProtocols = "serverproto,commonproto"; Buffer buff = Buffer.buffer("AAA"); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setWebsocketSubProtocols(serverSubProtocols)).websocketHandler(ws -> { assertEquals(path, ws.path()); assertNull(ws.subProtocol()); ws.accept(); assertEquals("commonproto", ws.subProtocol()); ws.writeFrame(WebSocketFrame.binaryFrame(buff, true)); }); server.listen(ar -> { assertTrue(ar.succeeded()); client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null, version, clientSubProtocols, ws -> { assertEquals("commonproto", ws.subProtocol()); final Buffer received = Buffer.buffer(); ws.handler(data -> { received.appendBuffer(data); if (received.length() == buff.length()) { assertEquals(buff, received); ws.close(); testComplete(); } }); }); }); await(); }
/** * Returns the websocket sub protocol selected by the websocket handshake. * <p/> * On the server, the value will be <code>null</code> when the handler receives the websocket callback as the * handshake will not be completed yet. * @return */ public String subProtocol() { String ret = delegate.subProtocol(); return ret; }
/** * Returns the websocket sub protocol selected by the websocket handshake. * <p/> * On the server, the value will be <code>null</code> when the handler receives the websocket callback as the * handshake will not be completed yet. * @return */ public String subProtocol() { String ret = delegate.subProtocol(); return ret; }
private void testValidSubProtocol(WebsocketVersion version) throws Exception { String path = "/some/path"; String clientSubProtocols = "clientproto,commonproto"; String serverSubProtocols = "serverproto,commonproto"; Buffer buff = Buffer.buffer("AAA"); server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setWebsocketSubProtocols(serverSubProtocols)).websocketHandler(ws -> { assertEquals(path, ws.path()); assertNull(ws.subProtocol()); ws.accept(); assertEquals("commonproto", ws.subProtocol()); ws.writeFrame(WebSocketFrame.binaryFrame(buff, true)); }); server.listen(ar -> { assertTrue(ar.succeeded()); client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, path, null, version, clientSubProtocols, ws -> { assertEquals("commonproto", ws.subProtocol()); final Buffer received = Buffer.buffer(); ws.handler(data -> { received.appendBuffer(data); if (received.length() == buff.length()) { assertEquals(buff, received); ws.close(); testComplete(); } }); }); }); await(); }