Constructor and Description |
---|
RealWebSocket(boolean isClient,
okio.BufferedSource source,
okio.BufferedSink sink,
Random random,
Executor replyExecutor,
WebSocketListener listener,
String url) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
close()
Perform any tear-down work (close the connection, shutdown executors).
|
void |
close(int code,
String reason)
Send a close frame to the server.
|
boolean |
readMessage()
Read a single message from the web socket and deliver it to the listener.
|
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.
|
void |
sendPong(okio.Buffer payload)
Send an unsolicited pong with the specified payload.
|
public RealWebSocket(boolean isClient, okio.BufferedSource source, okio.BufferedSink sink, Random random, Executor replyExecutor, WebSocketListener listener, String url)
public boolean readMessage()
public void sendMessage(RequestBody message) throws IOException
WebSocket
The content type of message
should be either
WebSocket.TEXT
or WebSocket.BINARY
.
sendMessage
in interface WebSocket
IOException
- if unable to write the message. Clients must call WebSocket.close(int, java.lang.String)
when this
happens to ensure resources are cleaned up.public void sendPing(okio.Buffer payload) throws IOException
WebSocket
sendPing
in interface WebSocket
IOException
- if unable to write the ping. Clients must call WebSocket.close(int, java.lang.String)
when this
happens to ensure resources are cleaned up.public void sendPong(okio.Buffer payload) throws IOException
IOException
public void close(int code, String reason) throws IOException
WebSocket
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.
close
in interface WebSocket
IOException
- if unable to write the close message. Resources will still be freed.protected abstract void close() throws IOException
IOException
Copyright © 2017. All rights reserved.