public interface IWebSocketClientContext
WebSocketListener
.Modifier and Type | Method and Description |
---|---|
void |
closeConnection()
Closes connection with the client.
|
Event<java.lang.Object> |
connectionClosed()
The event is invoked when the connection with the client was closed.
|
java.net.InetSocketAddress |
getClientEndPoint()
Returns the IP address and port of the connected client.
|
java.util.Map<java.lang.String,java.lang.String> |
getHeaderFields()
Returns the readonly dictionary.
|
int |
getReceiveTimeout()
Gets the receive timeout in milliseconds.
|
int |
getSendTimeout()
Gets the send timeout in milliseconds.
|
java.net.URI |
getUri()
Returns URI of this connection including query parameters sent from by the client.
|
boolean |
isConnected()
Returns true if the client is connected.
|
Event<java.lang.Object> |
pongReceived()
The event is invoked when the pong message was received.
|
WebSocketMessage |
receiveMessage()
Waits until a message is received from the client.
|
void |
sendMessage(java.lang.Object data)
Sends message to the client.
|
void |
sendMessage(java.lang.Object data,
boolean isFinal)
Sends message to the client.
|
void |
sendPing()
Pings the client.
|
void |
sendPong()
Sends unsolicited pong to the client.
|
void |
setReceiveTimeout(int receiveTimeout)
Sets the receive timeout in milliseconds.
|
void |
setSendTimeout(int sendTimeout)
Sets the send timeout in milliseconds.
|
Event<java.lang.Object> connectionClosed()
Event<java.lang.Object> pongReceived()
java.net.InetSocketAddress getClientEndPoint()
boolean isConnected()
java.net.URI getUri()
java.util.Map<java.lang.String,java.lang.String> getHeaderFields()
void setSendTimeout(int sendTimeout)
sendTimeout
- int getSendTimeout()
void setReceiveTimeout(int receiveTimeout) throws java.lang.Exception
receiveTimeout
- java.lang.Exception
int getReceiveTimeout() throws java.lang.Exception
java.lang.Exception
void sendMessage(java.lang.Object data) throws java.lang.Exception
data
- message to be sent to the client. Must be byte[] or string.java.lang.Exception
- If sending of the message failed.void sendMessage(java.lang.Object data, boolean isFinal) throws java.lang.Exception
void ProcessConnection(IWebSocketClientContext clientContext)
{
...
// Send the first part of the message.
clientContext.sendMessage("Hello ", false);
// Send the second part.
clientContext.sendMessage("wo", false);
// Send the third final part.
clientContext.sendMessage("rld.", true);
...
}
data
- message to be sent to the client. The message can be byte[] or string.isFinal
- true if this is the last part of the message.java.lang.Exception
- If sending of the message failed.WebSocketMessage receiveMessage() throws java.lang.Exception
void ProcessConnection(IWebSocketClientContext clientContext)
{
// The loop waiting for incoming messages.
// Note: The waiting thread is released when the connection is closed.
WebSocketMessage aWebSocketMessage;
while ((aWebSocketMessage = clientContext.receiveMessage()) != null)
{
if (aWebSocketMessage.isText())
{
// Wait until all data frames are collected
// and return the message.
String aMessage = aWebSocketMessage.getWholeTextMessage();
...
}
}
}
java.lang.Exception
void sendPing() throws java.lang.Exception
java.lang.Exception
void sendPong() throws java.lang.Exception
java.lang.Exception
void closeConnection()