Interface WebSocket
-
public interface WebSocket
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
WebSocket.Builder
static interface
WebSocket.Listener
Callback methods for websocket events.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description long
queueSize()
Returns the size in bytes of all messages enqueued to be transmitted to the server.void
request()
Used to receive more onMessage orWebSocket.Listener.onClose(WebSocket, int, String)
events after the initial message is receivedboolean
send(ByteBuffer buffer)
Send some data.boolean
sendClose(int code, String reason)
Send a close message.static URI
toWebSocketUri(URI httpUri)
Converts http or https URIs to ws or wss URIs.
-
-
-
Method Detail
-
send
boolean send(ByteBuffer buffer)
Send some data. The buffer will be copied if needed by the implementation to allow for modifications after this call.- Returns:
- true if the message was successfully enqueued.
-
sendClose
boolean sendClose(int code, String reason)
Send a close message. If successful, the output side will then be closed. After a timeout the input side will automatically be shutdown if it isn't already shutdown by the remote side.- Returns:
- true if the message was successfully enqueued.
-
queueSize
long queueSize()
Returns the size in bytes of all messages enqueued to be transmitted to the server. This doesn't include framing overhead.
-
request
void request()
Used to receive more onMessage orWebSocket.Listener.onClose(WebSocket, int, String)
events after the initial message is receivedrequest is implicitly called by
WebSocket.Listener.onOpen(WebSocket)
depending on the websocket implementation request may trigger immediate / concurrent delivery of the close event - this means you'll generally want to call this method once you've completed the consumption of the current event.
-
toWebSocketUri
static URI toWebSocketUri(URI httpUri)
Converts http or https URIs to ws or wss URIs.Clients such as JDK or Jetty require URIs to be performed to the ws protocol, other clients perform this same transformation automatically.
- Parameters:
httpUri
- the original URI to transform.- Returns:
- a new URI with the converted protocol (if applicable).
-
-