Interface Session
- All Superinterfaces:
AutoCloseable
,Closeable
,WebSocketPolicy
- All Known Implementing Classes:
WebSocketSession
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Request a close of the current conversation with a normal status code and no reason phrase.void
Send a websocket Close frame, with status code.default void
close
(int statusCode, String reason, WriteCallback callback) Send a websocket Close frame, with status code.void
close
(CloseStatus closeStatus) Request Close the current conversation, giving a reason for the closure.void
Issue a harsh disconnect of the underlying connection.The Local Socket Address for the active Sessiondefault WebSocketPolicy
Access the (now read-only)WebSocketPolicy
in use for this connection.Returns the version of the websocket protocol currently being used.Return a reference to the RemoteEndpoint object representing the other end of this conversation.The Remote Socket Address for the active SessionGet the UpgradeRequest used to create this sessionGet the UpgradeResponse used to create this sessionboolean
isOpen()
Return true if and only if the underlying socket is open.boolean
isSecure()
Return true if and only if the underlying socket is using a secure transport.suspend()
Suspend the delivery of incoming WebSocket frames.Methods inherited from interface org.eclipse.jetty.websocket.api.WebSocketPolicy
getBehavior, getIdleTimeout, getInputBufferSize, getMaxBinaryMessageSize, getMaxFrameSize, getMaxTextMessageSize, getOutputBufferSize, isAutoFragment, setAutoFragment, setIdleTimeout, setInputBufferSize, setMaxBinaryMessageSize, setMaxFrameSize, setMaxTextMessageSize, setOutputBufferSize
-
Method Details
-
close
void close()Request a close of the current conversation with a normal status code and no reason phrase.This will enqueue a graceful close to the remote endpoint.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- See Also:
-
close
Request Close the current conversation, giving a reason for the closure. Note the websocket spec defines the acceptable uses of status codes and reason phrases.This will enqueue a graceful close to the remote endpoint.
- Parameters:
closeStatus
- the reason for the closure- See Also:
-
close
Send a websocket Close frame, with status code.This will enqueue a graceful close to the remote endpoint.
- Parameters:
statusCode
- the status codereason
- the (optional) reason. (can be null for no reason)- See Also:
-
close
Send a websocket Close frame, with status code.This will enqueue a graceful close to the remote endpoint.
- Parameters:
statusCode
- the status codereason
- the (optional) reason. (can be null for no reason)callback
- the callback to track close frame sent (or failed)- See Also:
-
disconnect
void disconnect()Issue a harsh disconnect of the underlying connection.This will terminate the connection, without sending a websocket close frame.
Once called, any read/write activity on the websocket from this point will be indeterminate.
Once the underlying connection has been determined to be closed, the various onClose() events (either
WebSocketConnectionListener.onWebSocketClose(int, String)
orOnWebSocketClose
) will be called on your websocket.- See Also:
-
getLocalAddress
SocketAddress getLocalAddress()The Local Socket Address for the active SessionDo not assume that this will return a
InetSocketAddress
in all cases. Use of various proxies, and even UnixSockets can result a SocketAddress being returned without supportingInetSocketAddress
- Returns:
- the SocketAddress for the local connection, or null if not supported by Session
-
getPolicy
Access the (now read-only)WebSocketPolicy
in use for this connection.- Returns:
- the policy in use
-
getProtocolVersion
String getProtocolVersion()Returns the version of the websocket protocol currently being used. This is taken as the value of the Sec-WebSocket-Version header used in the opening handshake. i.e. "13".- Returns:
- the protocol version
-
getRemote
RemoteEndpoint getRemote()Return a reference to the RemoteEndpoint object representing the other end of this conversation.- Returns:
- the remote endpoint
-
getRemoteAddress
SocketAddress getRemoteAddress()The Remote Socket Address for the active SessionDo not assume that this will return a
InetSocketAddress
in all cases. Use of various proxies, and even UnixSockets can result a SocketAddress being returned without supportingInetSocketAddress
- Returns:
- the SocketAddress for the remote connection, or null if not supported by Session
-
getUpgradeRequest
UpgradeRequest getUpgradeRequest()Get the UpgradeRequest used to create this session- Returns:
- the UpgradeRequest used to create this session
-
getUpgradeResponse
UpgradeResponse getUpgradeResponse()Get the UpgradeResponse used to create this session- Returns:
- the UpgradeResponse used to create this session
-
isOpen
boolean isOpen()Return true if and only if the underlying socket is open.- Returns:
- whether the session is open
-
isSecure
boolean isSecure()Return true if and only if the underlying socket is using a secure transport.- Returns:
- whether its using a secure transport
-
suspend
SuspendToken suspend()Suspend the delivery of incoming WebSocket frames.If this is called from inside the scope of the message handler the suspend takes effect immediately. If suspend is called outside the scope of the message handler then the call may take effect after 1 more frame is delivered.
- Returns:
- the suspend token suitable for resuming the reading of data on the connection.
-