public final class WebSocketEcho extends Object implements WebSocketListener
| Constructor and Description |
|---|
WebSocketEcho() |
| Modifier and Type | Method and Description |
|---|---|
static void |
main(String... args) |
void |
onClose(int code,
String reason)
Called when the server sends a close message.
|
void |
onFailure(IOException e,
Response response)
Called when the transport or protocol layer of this web socket errors during communication.
|
void |
onMessage(ResponseBody message)
Called when a server message is received.
|
void |
onOpen(WebSocket webSocket,
Response response)
Called when the request has successfully been upgraded to a web socket.
|
void |
onPong(okio.Buffer payload)
Called when a server pong is received.
|
public void onOpen(WebSocket webSocket, Response response)
WebSocketListenerclose
callbacks start.
Do not use this callback to write to the web socket. Start a new thread or use another thread in your application.
onOpen in interface WebSocketListenerpublic void onMessage(ResponseBody message) throws IOException
WebSocketListenertype indicates whether the
payload should be interpreted as UTF-8 text or binary data.
Implementations must call source.close() before returning. This
indicates completion of parsing the message payload and will consume any remaining bytes in
the message.
The content type of message will be either
WebSocket.TEXT or WebSocket.BINARY which indicates the format of the message.
onMessage in interface WebSocketListenerIOExceptionpublic void onPong(okio.Buffer payload)
WebSocketListenerWebSocket.sendPing(Buffer) but might also be unsolicited.onPong in interface WebSocketListenerpublic void onClose(int code,
String reason)
WebSocketListenerclose() or as an unprompted
message from the server.onClose in interface WebSocketListenercode - The RFC-compliant
status code.reason - Reason for close or an empty string.public void onFailure(IOException e, Response response)
WebSocketListeneronFailure in interface WebSocketListenerresponse - Present when the failure is a direct result of the response (e.g., failed
upgrade, non-101 response code, etc.). null otherwise.public static void main(String... args) throws IOException
IOExceptionCopyright © 2017. All Rights Reserved.