Interface BaseWebSocketExchange<A extends ExchangeContext>
- Type Parameters:
A
- the type of the exchange context
- All Known Subinterfaces:
Web2SocketExchange<A>
,WebSocketExchange<A>
,WebSocketExchange<A>
Represents a WebSocket exchange between a client and a server.
A WebSocket exchange is bidirectional and as a result provided an BaseWebSocketExchange.Inbound
and an BaseWebSocketExchange.Outbound
exposing WebSocket frames and messages respectively received and sent by a client or a
server.
A WebSocket exchange can be created from an HTTP server exchange once the WebSocket opening handshake has completed or from an HTTP client to open a WebSocket connection to an HTTP server.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Represents the inbound part of a WebSocket exchange.static interface
Represents the outbound part of a WebSocket exchange. -
Method Summary
Modifier and TypeMethodDescriptiondefault void
close()
Closes the WebSocket with the normal status (1000
).default void
close
(short code) Closes the WebSocket with the specified status code.void
Closes the WebSocket with specified status code and reason.default void
close
(WebSocketStatus status) Closes the WebSocket with the specified status.default void
close
(WebSocketStatus status, String reason) Closes the WebSocket with specified status and reason.default void
Closes the WebSocket with the normal status (1000
) and the specified reason.context()
Returns the context attached to the exchange.Returns the subprotocol that was negotiated with the client during the opening handshake.inbound()
Returns the inbound part of the WebSocket exchange.outbound()
Returns the outbound part of the WebSocket exchange.
-
Method Details
-
context
A context()Returns the context attached to the exchange.
- Returns:
- the exchange context or null
-
getSubProtocol
String getSubProtocol()Returns the subprotocol that was negotiated with the client during the opening handshake.
Note that the handshake will fail and the WebSocket connection closed if no subprotocols could have been negotiated.
- Returns:
- a subprotocol or null if no subprotocol was specified by both client and server
-
inbound
BaseWebSocketExchange.Inbound inbound()Returns the inbound part of the WebSocket exchange.
This basically corresponds to the stream of WebSocket frames received by the server from the client or by the client from the server.
- Returns:
- the inbound part
-
outbound
BaseWebSocketExchange.Outbound outbound()Returns the outbound part of the WebSocket exchange.
This basically corresponds to the stream of WebSocket frames sent by the server to the client or by the client to the server.
- Returns:
- the outbound part
-
close
default void close()Closes the WebSocket with the normal status (
1000
).If the WebSocket was already closed, this method does nothing.
-
close
Closes the WebSocket with the specified status.
If the WebSocket was already closed, this method does nothing.
- Parameters:
status
- a WebSocket close status
-
close
default void close(short code) Closes the WebSocket with the specified status code.
If the WebSocket was already closed, this method does nothing.
- Parameters:
code
- a WebSocket close status code
-
close
Closes the WebSocket with the normal status (
1000
) and the specified reason.A WebSocket close frame must have a payload length of 125 bytes or less, when
code + reason
exceeds this limit, the reason shall be truncated.If the WebSocket was already closed, this method does nothing.
- Parameters:
reason
- a close reason
-
close
Closes the WebSocket with specified status and reason.
A WebSocket close frame must have a payload length of 125 bytes or less, when
code + reason
exceeds this limit, the reason shall be truncated.If the WebSocket was already closed, this method does nothing.
- Parameters:
status
- a WebSocket close statusreason
- a WebSocket close status code
-
close
Closes the WebSocket with specified status code and reason.
A WebSocket close frame must have a payload length of 125 bytes or less, when
code + reason
exceeds this limit, the reason shall be truncated.A WebSocket close frame must have a payload length of 125 bytes or less, when
code + reason
exceeds this limit, the reason shall be truncated.If the WebSocket was already closed, this method does nothing.
- Parameters:
code
- a WebSocket close status codereason
- a WebSocket close status code
-