public final class RealWebSocket extends Object implements WebSocket, WebSocketReader.FrameCallback
| Modifier and Type | Class and Description |
|---|---|
static class |
RealWebSocket.Streams |
WebSocket.Factory| Constructor and Description |
|---|
RealWebSocket(Request request,
WebSocketListener listener,
Random random) |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Immediately and violently release resources held by this web socket, discarding any enqueued
messages.
|
boolean |
close(int code,
String reason)
Attempts to initiate a graceful shutdown of this web socket.
|
void |
connect(OkHttpClient client) |
void |
failWebSocket(Exception e,
Response response) |
void |
initReaderAndWriter(String name,
long pingIntervalMillis,
RealWebSocket.Streams streams) |
void |
loopReader()
Receive frames until there are no more.
|
void |
onReadClose(int code,
String reason) |
void |
onReadMessage(okio.ByteString bytes) |
void |
onReadMessage(String text) |
void |
onReadPing(okio.ByteString payload) |
void |
onReadPong(okio.ByteString buffer) |
long |
queueSize()
Returns the size in bytes of all messages enqueued to be transmitted to the server.
|
Request |
request()
Returns the original request that initiated this web socket.
|
boolean |
send(okio.ByteString bytes)
Attempts to enqueue
bytes to be sent as a the data of a binary (type 0x2)
message. |
boolean |
send(String text)
Attempts to enqueue
text to be UTF-8 encoded and sent as a the data of a text (type
0x1) message. |
public RealWebSocket(Request request, WebSocketListener listener, Random random)
public Request request()
WebSocketpublic long queueSize()
WebSocketpublic void cancel()
WebSocketpublic void connect(OkHttpClient client)
public void initReaderAndWriter(String name, long pingIntervalMillis, RealWebSocket.Streams streams) throws IOException
IOExceptionpublic void loopReader()
throws IOException
IOExceptionpublic void onReadMessage(String text) throws IOException
onReadMessage in interface WebSocketReader.FrameCallbackIOExceptionpublic void onReadMessage(okio.ByteString bytes)
throws IOException
onReadMessage in interface WebSocketReader.FrameCallbackIOExceptionpublic void onReadPing(okio.ByteString payload)
onReadPing in interface WebSocketReader.FrameCallbackpublic void onReadPong(okio.ByteString buffer)
onReadPong in interface WebSocketReader.FrameCallbackpublic void onReadClose(int code,
String reason)
onReadClose in interface WebSocketReader.FrameCallbackpublic boolean send(String text)
WebSockettext to be UTF-8 encoded and sent as a the data of a text (type
0x1) message.
This method returns true if the message was enqueued. Messages that would overflow the outgoing message buffer will be rejected and trigger a graceful shutdown of this web socket. This method returns false in that case, and in any other case where this web socket is closing, closed, or canceled.
This method returns immediately.
public boolean send(okio.ByteString bytes)
WebSocketbytes to be sent as a the data of a binary (type 0x2)
message.
This method returns true if the message was enqueued. Messages that would overflow the outgoing message buffer will be rejected and trigger a graceful shutdown of this web socket. This method returns false in that case, and in any other case where this web socket is closing, closed, or canceled.
This method returns immediately.
public boolean close(int code,
String reason)
WebSocketWebSocket.send(java.lang.String) will
return false and their messages will not be enqueued.
This returns true if a graceful shutdown was initiated by this call. It returns false and if a graceful shutdown was already underway or if the web socket is already closed or canceled.
close in interface WebSocketcode - Status code as defined by Section 7.4 of RFC 6455 or 0.reason - Reason for shutting down or null.Copyright © 2017. All Rights Reserved.