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,
long pingIntervalMillis) |
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,
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, long pingIntervalMillis)
public Request request()
WebSocket
public long queueSize()
WebSocket
public void cancel()
WebSocket
public void connect(OkHttpClient client)
public void initReaderAndWriter(String name, RealWebSocket.Streams streams) throws IOException
IOException
public void loopReader() throws IOException
IOException
public void onReadMessage(String text) throws IOException
onReadMessage
in interface WebSocketReader.FrameCallback
IOException
public void onReadMessage(okio.ByteString bytes) throws IOException
onReadMessage
in interface WebSocketReader.FrameCallback
IOException
public void onReadPing(okio.ByteString payload)
onReadPing
in interface WebSocketReader.FrameCallback
public void onReadPong(okio.ByteString buffer)
onReadPong
in interface WebSocketReader.FrameCallback
public void onReadClose(int code, String reason)
onReadClose
in interface WebSocketReader.FrameCallback
public boolean send(String text)
WebSocket
text
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)
WebSocket
bytes
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 (16 MiB) 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)
WebSocket
WebSocket.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 WebSocket
code
- Status code as defined by Section 7.4 of RFC 6455.reason
- Reason for shutting down or null
.Copyright © 2018. All rights reserved.