public final class WebSocketWriter extends Object
This class is partially thread safe. Only a single "main" thread should be sending messages via
calls to newMessageSink(com.squareup.okhttp.internal.ws.WebSocket.PayloadType)
or sendMessage(com.squareup.okhttp.internal.ws.WebSocket.PayloadType, okio.Buffer)
as well as any calls to
writePing(okio.Buffer)
or writeClose(int, java.lang.String)
. Other threads may call writePing(okio.Buffer)
,
writePong(okio.Buffer)
, or writeClose(int, java.lang.String)
which will interleave on the wire with frames from
the main thread.
Constructor and Description |
---|
WebSocketWriter(boolean isClient,
okio.BufferedSink sink,
Random random) |
Modifier and Type | Method and Description |
---|---|
boolean |
isClosed() |
okio.BufferedSink |
newMessageSink(WebSocket.PayloadType type)
Stream a message payload as a series of frames.
|
void |
sendMessage(WebSocket.PayloadType type,
okio.Buffer payload)
Send a message payload as a single frame.
|
void |
writeClose(okio.Buffer payload)
Send a close frame with optional payload.
|
void |
writeClose(int code,
String reason)
Send a close frame with optional code and reason.
|
void |
writePing(okio.Buffer payload)
Send a ping with the supplied
payload . |
void |
writePong(okio.Buffer payload)
Send a pong with the supplied
payload . |
public WebSocketWriter(boolean isClient, okio.BufferedSink sink, Random random)
public boolean isClosed()
public void writePing(okio.Buffer payload) throws IOException
payload
. Payload may be null
IOException
public void writePong(okio.Buffer payload) throws IOException
payload
. Payload may be null
IOException
public void writeClose(int code, String reason) throws IOException
code
- Status code as defined by
Section 7.4 of RFC 6455 or
0
.reason
- Reason for shutting down or null
. code
is required if set.IOException
public void writeClose(okio.Buffer payload) throws IOException
IOException
public okio.BufferedSink newMessageSink(WebSocket.PayloadType type)
public void sendMessage(WebSocket.PayloadType type, okio.Buffer payload) throws IOException
IOException
Copyright © 2015. All rights reserved.