public class WsTest extends ComponentVerticle { | |
@Inject | |
protected WsTest(ConfigFactory configFactory) { | |
super(configFactory); | |
} | |
@Override | |
public void start() throws Exception { | |
super.start(); | |
Router router = Router.router(vertx); | |
router | |
.getWithRegex("/ws/.*") | |
.handler(rc -> { | |
HttpServerRequest req = rc.request(); | |
String connectionHeader = req.headers().get(io.vertx.core.http.HttpHeaders.CONNECTION); | |
if (connectionHeader == null || !connectionHeader.toLowerCase().contains("upgrade")) { | |
rc.response().setStatusCode(400); | |
rc.response().end("Can \"Upgrade\" only to \"WebSocket\"."); | |
} else { | |
ServerWebSocket ws = rc.request().upgrade(); | |
ws.frameHandler(msg -> { | |
System.out.println(msg); | |
}); | |
} | |
}); | |
vertx.createHttpServer() | |
.requestHandler(router::accept) | |
.listen(8765); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment