public interface WebSocketListener
WebSocket
.Modifier and Type | Method and Description |
---|---|
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.
|
void onOpen(WebSocket webSocket, Response response)
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.
void onFailure(IOException e, Response response)
response
- Present when the failure is a direct result of the response (e.g., failed
upgrade, non-101 response code, etc.). null
otherwise.void onMessage(ResponseBody message) throws IOException
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.
IOException
void onPong(okio.Buffer payload)
WebSocket.sendPing(Buffer)
but might also be unsolicited.void onClose(int code, String reason)
close()
or as an unprompted
message from the server.code
- The RFC-compliant
status code.reason
- Reason for close or an empty string.Copyright © 2016. All rights reserved.