Next: , Previous: Connecting to server, Up: Top


4 Using an established socket

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.

Naming convention

Throughout this chapter WebSocket will refer to both websocket4j.client.WebSocket and websocket4j.server.WebSocket.

Sending messages

To send messages you can use sendMessage(String) : void method of WebSocket. This method immediately sends given string to the other party.

Receiving

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.