public class WebSocket
This class represents a web socket.
Modifier and Type | Class and Description |
---|---|
static class |
WebSocket.Companion
The companion object.
|
Modifier and Type | Field and Description |
---|---|
static WebSocket.Companion |
Companion
The companion object.
|
static int |
MAX_PAYLOAD_SIZE
The maximum payload size in bytes.
|
static long |
PING_INTERVAL
The ping interval in seconds.
|
Constructor and Description |
---|
WebSocket(java.lang.String webSocketURL,
SSLConfiguration sslConfiguration,
WebSocket.Listener listener)
Creates an instance of
class WebSocket . |
Modifier and Type | Method and Description |
---|---|
boolean |
connect()
Connects the web socket to the remote host.
|
protected okhttp3.WebSocket |
createWebSocket()
Creates and returns a web socket.
|
boolean |
disconnect()
Disconnects the web socket from the remote host.
|
WebSocket.State |
getState()
The current state of the web socket.
|
java.lang.String |
getWebSocketURL()
The web socket URL.
|
void |
onClosed(okhttp3.WebSocket webSocket,
int code,
java.lang.String reason) |
void |
onFailure(okhttp3.WebSocket webSocket,
java.lang.Throwable throwable,
okhttp3.Response response) |
void |
onMessage(okhttp3.WebSocket webSocket,
java.lang.String text) |
void |
onOpen(okhttp3.WebSocket webSocket,
okhttp3.Response response) |
boolean |
send(java.lang.String message)
Sends a message on the web socket.
|
public static int MAX_PAYLOAD_SIZE
The maximum payload size in bytes.
public static long PING_INTERVAL
The ping interval in seconds.
public static WebSocket.Companion Companion
The companion object.
public WebSocket(@NotNull java.lang.String webSocketURL, @Nullable SSLConfiguration sslConfiguration, @NotNull WebSocket.Listener listener)
Creates an instance of class WebSocket
.
webSocketURL
- The web socket URL.sslConfiguration
- The SSL configuration if the web socket is secure, or null
if is not secure.listener
- The listener of the web socket events.class WebSocket
@NotNull public WebSocket.State getState()
The current state of the web socket.
public boolean connect()
Connects the web socket to the remote host.
true
is the web socket connected successfully, otherwise false
.public boolean disconnect()
Disconnects the web socket from the remote host.
true
is the web socket disconnected successfully, otherwise false
.public boolean send(@NotNull java.lang.String message)
Sends a message on the web socket.
message
- The message to send.true
if the message was sent successfully, otherwise false
.@NotNull protected okhttp3.WebSocket createWebSocket()
Creates and returns a web socket.
public void onOpen(@NotNull okhttp3.WebSocket webSocket, @NotNull okhttp3.Response response)
public void onMessage(@NotNull okhttp3.WebSocket webSocket, @NotNull java.lang.String text)
public void onClosed(@NotNull okhttp3.WebSocket webSocket, int code, @NotNull java.lang.String reason)
public void onFailure(@NotNull okhttp3.WebSocket webSocket, @NotNull java.lang.Throwable throwable, @Nullable okhttp3.Response response)
@NotNull public java.lang.String getWebSocketURL()
The web socket URL.