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)
WebSocketListener
close
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 WebSocketListener
public void onMessage(ResponseBody message) throws IOException
WebSocketListener
type
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 WebSocketListener
IOException
public void onPong(okio.Buffer payload)
WebSocketListener
WebSocket.sendPing(Buffer)
but might also be unsolicited.onPong
in interface WebSocketListener
public void onClose(int code, String reason)
WebSocketListener
close()
or as an unprompted
message from the server.onClose
in interface WebSocketListener
code
- The RFC-compliant
status code.reason
- Reason for close or an empty string.public void onFailure(IOException e, Response response)
WebSocketListener
onFailure
in interface WebSocketListener
response
- 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
IOException
Copyright © 2017. All rights reserved.