Class WebSocketClientHandshaker00
java.lang.Object
io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker
io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker00
Performs client side opening and closing handshakes for web socket specification version draft-ietf-hybi-thewebsocketprotocol- 00
A very large portion of this code was taken from the Netty 3.2 HTTP example.
-
Field Summary
Fields inherited from class WebSocketClientHandshaker
customHeaders, DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS, generateOriginHeaderModifier and TypeFieldDescriptionprotected final HttpHeadersprotected static final intprotected final boolean -
Constructor Summary
ConstructorsConstructorDescriptionWebSocketClientHandshaker00(URI webSocketURL, WebSocketVersion version, String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength) Creates a new instance with the specified destination WebSocket location and version to initiate.WebSocketClientHandshaker00(URI webSocketURL, WebSocketVersion version, String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis) Creates a new instance with the specified destination WebSocket location and version to initiate. -
Method Summary
Modifier and TypeMethodDescriptionprotected FullHttpRequestSends the opening request to the server: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
-
Constructor Details
-
WebSocketClientHandshaker00
public WebSocketClientHandshaker00(URI webSocketURL, WebSocketVersion version, String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength) Creates a new instance with the specified destination WebSocket location and version to initiate.- 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.customHeaders- Map of custom headers to add to the client requestmaxFramePayloadLength- Maximum length of a frame's payload
-
WebSocketClientHandshaker00
public WebSocketClientHandshaker00(URI webSocketURL, WebSocketVersion version, String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis) Creates a new instance with the specified destination WebSocket location and version to initiate.- 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.customHeaders- Map of custom headers to add to the client requestmaxFramePayloadLength- Maximum length of a frame's payloadforceCloseTimeoutMillis- 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 /demo HTTP/1.1 Upgrade: WebSocket Connection: Upgrade Host: example.com Origin: http://example.com Sec-WebSocket-Key1: 4 @1 46546xW%0l 1 5 Sec-WebSocket-Key2: 12998 5 Y3 1 .P00 ^n:ds[4U
- Specified by:
newHandshakeRequestin classWebSocketClientHandshaker
-
verify
Process server response:
HTTP/1.1 101 WebSocket Protocol Handshake Upgrade: WebSocket Connection: Upgrade Sec-WebSocket-Origin: http://example.com Sec-WebSocket-Location: ws://example.com/demo Sec-WebSocket-Protocol: sample 8jKS'y:G*Co,Wxa-
- 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
-