public interface WebSocket
Modifier and Type | Field and Description |
---|---|
static MediaType |
BINARY
A
MediaType indicating binary frames should be used when sending the message. |
static MediaType |
TEXT
A
MediaType indicating UTF-8 text frames should be used when sending the message. |
Modifier and Type | Method and Description |
---|---|
void |
close(int code,
String reason)
Send a close frame to the server.
|
void |
sendMessage(RequestBody message)
Send a message payload to the server.
|
void |
sendPing(okio.Buffer payload)
Send a ping to the server with optional payload.
|
static final MediaType TEXT
MediaType
indicating UTF-8 text frames should be used when sending the message.void sendMessage(RequestBody message) throws IOException
The content type of message
should be either
TEXT
or BINARY
.
IOException
- if unable to write the message. Clients must call close(int, java.lang.String)
when this
happens to ensure resources are cleaned up.IllegalStateException
- if not connected, already closed, or another writer is active.void sendPing(okio.Buffer payload) throws IOException
IOException
- if unable to write the ping. Clients must call close(int, java.lang.String)
when this
happens to ensure resources are cleaned up.IllegalStateException
- if already closed.void close(int code, String reason) throws IOException
The corresponding WebSocketListener
will continue to get messages until its
onClose()
method is called.
It is an error to call this method before calling close on an active writer. Calling this method more than once has no effect.
IOException
- if unable to write the close message. Resources will still be freed.IllegalStateException
- if already closed.Copyright © 2017. All Rights Reserved.