Hi,
I think you should have in mind that you are developing an event driven application, so when you get the websocket event you need to setup the various event handler your application will react to, here are a few examples:
1/ send message periodically (timer event)
websocket -> {
vertx.setPeriodic(1000, id -> {
websocket.writeTextMessage(“a message");
});
}
2/ react to an event bus message
websocket -> {
vertx.eventBus().handler(“the-address”, msg -> {
websocket.writeTextMessage(“a message");
});
}
keep in mind also to unregister handlers when the websocket closes, for instance:
1/
websocket -> {
long timerID = vertx.setPeriodic(1000, id -> { … });
websocket.closeHandler(v -> {
vertx.cancelTimer(timerID);
});
}
2/
websocket -> {
MessageConsumer<String> consumer = vertx.eventBus().handler(“the-address”, msg -> {
//
});
websocket.closeHandler(v -> {
consumer.unregister();
});
}
I hope it will help you to get you started with event driven application.
cheers
Julien