Class WebSocketClientHandshaker08
java.lang.Object
io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker
io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker08
Performs client side opening and closing handshakes for web socket specification version draft-ietf-hybi-thewebsocketprotocol- 10
-
Field Summary
FieldsFields inherited from class WebSocketClientHandshaker
customHeaders, DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS, generateOriginHeaderModifier and TypeFieldDescriptionprotected final HttpHeadersprotected static final intprotected final boolean -
Constructor Summary
ConstructorsConstructorDescriptionWebSocketClientHandshaker08(URI webSocketURL, WebSocketVersion version, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength) Creates a new instance.WebSocketClientHandshaker08(URI webSocketURL, WebSocketVersion version, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength, boolean performMasking, boolean allowMaskMismatch) Creates a new instance.WebSocketClientHandshaker08(URI webSocketURL, WebSocketVersion version, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength, boolean performMasking, boolean allowMaskMismatch, long forceCloseTimeoutMillis) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected FullHttpRequest/**protected WebSocketFrameDecoderReturns the decoder to use after handshake is complete.protected WebSocketFrameEncoderReturns the encoder to use after the handshake is complete.setForceCloseTimeoutMillis(long forceCloseTimeoutMillis) Sets timeout to close the connection if it was not closed by the server.protected voidverify(FullHttpResponse response) Process server response:Methods inherited from class WebSocketClientHandshaker
actualSubprotocol, close, close, close, close, expectedSubprotocol, finishHandshake, forceCloseTimeoutMillis, handshake, handshake, isForceCloseComplete, isHandshakeComplete, maxFramePayloadLength, processHandshake, processHandshake, upgradeUrl, uri, versionModifier and TypeMethodDescriptionReturns the subprotocol response sent by the server.close(ChannelHandlerContext ctx, CloseWebSocketFrame frame) Performs the closing handshakeclose(ChannelHandlerContext ctx, CloseWebSocketFrame frame, ChannelPromise promise) Performs the closing handshakeclose(Channel channel, CloseWebSocketFrame frame) Performs the closing handshake.close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) Performs the closing handshake When called from within aChannelHandleryou most likely want to useWebSocketClientHandshaker.close(ChannelHandlerContext, CloseWebSocketFrame, ChannelPromise).Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructorfinal voidfinishHandshake(Channel channel, FullHttpResponse response) Validates and finishes the opening handshake initiated byWebSocketClientHandshaker.handshake(Channel)}.longBegins the opening handshakefinal ChannelFuturehandshake(Channel channel, ChannelPromise promise) Begins the opening handshakeprotected booleanFlag to indicate if the closing handshake was initiated because of timeout.booleanFlag to indicate if the opening handshake is completeintReturns the max length for any frame's payloadfinal ChannelFutureprocessHandshake(Channel channel, HttpResponse response) Process the opening handshake initiated byWebSocketClientHandshaker.handshake(Channel)}.final ChannelFutureprocessHandshake(Channel channel, HttpResponse response, ChannelPromise promise) Process the opening handshake initiated byWebSocketClientHandshaker.handshake(Channel)}.protected StringupgradeUrl(URI wsURL) Return the constructed raw path for the giveURI.uri()Returns the URI to the web socket. e.g.version()Version of the web socket specification that is being used
-
Field Details
-
MAGIC_GUID
- See Also:
-
-
Constructor Details
-
WebSocketClientHandshaker08
public WebSocketClientHandshaker08(URI webSocketURL, WebSocketVersion version, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength) Creates a new instance.- Parameters:
webSocketURL- URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.version- Version of web socket specification to use to connect to the serversubprotocol- Sub protocol request sent to the server.allowExtensions- Allow extensions to be used in the reserved bits of the web socket framecustomHeaders- Map of custom headers to add to the client requestmaxFramePayloadLength- Maximum length of a frame's payload
-
WebSocketClientHandshaker08
public WebSocketClientHandshaker08(URI webSocketURL, WebSocketVersion version, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength, boolean performMasking, boolean allowMaskMismatch) Creates a new instance.- Parameters:
webSocketURL- URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.version- Version of web socket specification to use to connect to the serversubprotocol- Sub protocol request sent to the server.allowExtensions- Allow extensions to be used in the reserved bits of the web socket framecustomHeaders- Map of custom headers to add to the client requestmaxFramePayloadLength- Maximum length of a frame's payloadperformMasking- Whether to mask all written websocket frames. This must be set to true in order to be fully compatible with the websocket specifications. Client applications that communicate with a non-standard server which doesn't require masking might set this to false to achieve a higher performance.allowMaskMismatch- When set to true, frames which are not masked properly according to the standard will still be accepted
-
WebSocketClientHandshaker08
public WebSocketClientHandshaker08(URI webSocketURL, WebSocketVersion version, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength, boolean performMasking, boolean allowMaskMismatch, long forceCloseTimeoutMillis) Creates a new instance.- Parameters:
webSocketURL- URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.version- Version of web socket specification to use to connect to the serversubprotocol- Sub protocol request sent to the server.allowExtensions- Allow extensions to be used in the reserved bits of the web socket framecustomHeaders- Map of custom headers to add to the client requestmaxFramePayloadLength- Maximum length of a frame's payloadperformMasking- Whether to mask all written websocket frames. This must be set to true in order to be fully compatible with the websocket specifications. Client applications that communicate with a non-standard server which doesn't require masking might set this to false to achieve a higher performance.allowMaskMismatch- When set to true, frames which are not masked properly according to the standard will still be acceptedforceCloseTimeoutMillis- Close the connection if it was not closed by the server after timeout specified.
-
-
Method Details
-
newHandshakeRequest
/**Sends the opening request to the server:
GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Origin: http://example.com Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 8
- Specified by:
newHandshakeRequestin classWebSocketClientHandshaker
-
verify
Process server response:
HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= Sec-WebSocket-Protocol: chat
- Specified by:
verifyin classWebSocketClientHandshaker- Parameters:
response- HTTP response returned from the server for the request sent by beginOpeningHandshake00().- Throws:
WebSocketHandshakeException
-
newWebsocketDecoder
Description copied from class:WebSocketClientHandshakerReturns the decoder to use after handshake is complete.- Specified by:
newWebsocketDecoderin classWebSocketClientHandshaker
-
newWebSocketEncoder
Description copied from class:WebSocketClientHandshakerReturns the encoder to use after the handshake is complete.- Specified by:
newWebSocketEncoderin classWebSocketClientHandshaker
-
setForceCloseTimeoutMillis
Description copied from class:WebSocketClientHandshakerSets timeout to close the connection if it was not closed by the server.- Overrides:
setForceCloseTimeoutMillisin classWebSocketClientHandshaker- Parameters:
forceCloseTimeoutMillis- Close the connection if it was not closed by the server after timeout specified
-