Once a connection is established and you have an instance of either
websocket4j.client.WebSocket
, or
websocket4j.server.WebSocket
you can use them in uniform way to
send and receive messages.
Throughout this chapter WebSocket
will refer to both
websocket4j.client.WebSocket
and
websocket4j.server.WebSocket
.
To send messages you can use sendMessage(String) : void
method of
WebSocket. This method immediately sends given string to the other
party.
To receive messages you can use synchronous getMessage(void) :
String
method of WebSocket. This method waits until the other party
sends a message and then returns it.