Class WebSocketServerHandshaker
java.lang.Object
org.jboss.netty.handler.codec.http.websocketx.WebSocketServerHandshaker
- Direct Known Subclasses:
WebSocketServerHandshaker00
,WebSocketServerHandshaker07
,WebSocketServerHandshaker08
,WebSocketServerHandshaker13
Base class for server side web socket opening and closing handshakes
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ChannelFutureListener
ChannelFutureListener
which will callChannels.fireExceptionCaught(ChannelHandlerContext, Throwable)
if theChannelFuture
was not successful.private final long
private String
static final String
Use this as wildcard to support all requested sub-protocolsprivate final String[]
private final WebSocketVersion
private final String
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
WebSocketServerHandshaker
(WebSocketVersion version, String webSocketUrl, String subprotocols) Constructor using default valuesprotected
WebSocketServerHandshaker
(WebSocketVersion version, String webSocketUrl, String subprotocols, long maxFramePayloadLength) Constructor specifying the destination web socket location -
Method Summary
Modifier and TypeMethodDescriptionabstract ChannelFuture
close
(Channel channel, CloseWebSocketFrame frame) Performs the closing handshakelong
Returns the max length for any frame's payloadReturns the selected subprotocol.Returns the CSV of supported sub protocolsReturns the version of the specification being supportedReturns the URL of the web socketabstract ChannelFuture
handshake
(Channel channel, HttpRequest req) Performs the opening handshakeprotected String
selectSubprotocol
(String requestedSubprotocols) Selects the first matching supported sub protocolprotected void
setSelectedSubprotocol
(String value) protected ChannelFuture
writeHandshakeResponse
(Channel channel, HttpResponse res, ChannelHandler encoder, ChannelHandler decoder) Upgrades the connection and send the handshake response.
-
Field Details
-
SUB_PROTOCOL_WILDCARD
Use this as wildcard to support all requested sub-protocols- See Also:
-
webSocketUrl
-
subprotocols
-
version
-
maxFramePayloadLength
private final long maxFramePayloadLength -
selectedSubprotocol
-
HANDSHAKE_LISTENER
ChannelFutureListener
which will callChannels.fireExceptionCaught(ChannelHandlerContext, Throwable)
if theChannelFuture
was not successful.
-
-
Constructor Details
-
WebSocketServerHandshaker
protected WebSocketServerHandshaker(WebSocketVersion version, String webSocketUrl, String subprotocols) Constructor using default values- Parameters:
version
- the protocol versionwebSocketUrl
- URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.subprotocols
- CSV of supported protocols. Null if sub protocols not supported.
-
WebSocketServerHandshaker
protected WebSocketServerHandshaker(WebSocketVersion version, String webSocketUrl, String subprotocols, long maxFramePayloadLength) Constructor specifying the destination web socket location- Parameters:
version
- the protocol versionwebSocketUrl
- URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.subprotocols
- CSV of supported protocols. Null if sub protocols not supported.maxFramePayloadLength
- Maximum length of a frame's payload
-
-
Method Details
-
getWebSocketUrl
Returns the URL of the web socket -
getSubprotocols
Returns the CSV of supported sub protocols -
getVersion
Returns the version of the specification being supported -
getMaxFramePayloadLength
public long getMaxFramePayloadLength()Returns the max length for any frame's payload -
handshake
Performs the opening handshake- Parameters:
channel
- Channelreq
- HTTP Request
-
writeHandshakeResponse
protected ChannelFuture writeHandshakeResponse(Channel channel, HttpResponse res, ChannelHandler encoder, ChannelHandler decoder) Upgrades the connection and send the handshake response. -
close
Performs the closing handshake- Parameters:
channel
- Channelframe
- Closing Frame that was received
-
selectSubprotocol
Selects the first matching supported sub protocol- Parameters:
requestedSubprotocols
- CSV of protocols to be supported. e.g. "chat, superchat"- Returns:
- First matching supported sub protocol. Null if not found.
-
getSelectedSubprotocol
Returns the selected subprotocol. Null if no subprotocol has been selected.This is only available AFTER handshake() has been called.
-
setSelectedSubprotocol
-