Class WebSocketClientHandshaker00
- java.lang.Object
-
- io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker
-
- io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker00
-
public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker
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 Modifier and Type Field Description private ByteBufexpectedChallengeResponseBytesprivate static AsciiStringWEBSOCKET-
Fields inherited from class io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker
customHeaders, DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS
-
-
Constructor Summary
Constructors Constructor Description WebSocketClientHandshaker00(java.net.URI webSocketURL, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength)Creates a new instance with the specified destination WebSocket location and version to initiate.WebSocketClientHandshaker00(java.net.URI webSocketURL, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis)Creates a new instance with the specified destination WebSocket location and version to initiate.WebSocketClientHandshaker00(java.net.URI webSocketURL, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl)Creates a new instance with the specified destination WebSocket location and version to initiate.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringinsertRandomCharacters(java.lang.String key)private static java.lang.StringinsertSpaces(java.lang.String key, int spaces)protected FullHttpRequestnewHandshakeRequest()Sends the opening request to the server:protected WebSocketFrameDecodernewWebsocketDecoder()Returns the decoder to use after handshake is complete.protected WebSocketFrameEncodernewWebSocketEncoder()Returns the encoder to use after the handshake is complete.WebSocketClientHandshaker00setForceCloseTimeoutMillis(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 io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker
actualSubprotocol, close, close, expectedSubprotocol, finishHandshake, forceCloseTimeoutMillis, handshake, handshake, isForceCloseComplete, isHandshakeComplete, maxFramePayloadLength, processHandshake, processHandshake, upgradeUrl, uri, version, websocketHostValue, websocketOriginValue
-
-
-
-
Field Detail
-
WEBSOCKET
private static final AsciiString WEBSOCKET
-
expectedChallengeResponseBytes
private ByteBuf expectedChallengeResponseBytes
-
-
Constructor Detail
-
WebSocketClientHandshaker00
public WebSocketClientHandshaker00(java.net.URI webSocketURL, WebSocketVersion version, java.lang.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(java.net.URI webSocketURL, WebSocketVersion version, java.lang.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
-
WebSocketClientHandshaker00
WebSocketClientHandshaker00(java.net.URI webSocketURL, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl)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 specifiedabsoluteUpgradeUrl- Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP
-
-
Method Detail
-
newHandshakeRequest
protected FullHttpRequest 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
protected void verify(FullHttpResponse response)
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
-
insertRandomCharacters
private static java.lang.String insertRandomCharacters(java.lang.String key)
-
insertSpaces
private static java.lang.String insertSpaces(java.lang.String key, int spaces)
-
newWebsocketDecoder
protected WebSocketFrameDecoder newWebsocketDecoder()
Description copied from class:WebSocketClientHandshakerReturns the decoder to use after handshake is complete.- Specified by:
newWebsocketDecoderin classWebSocketClientHandshaker
-
newWebSocketEncoder
protected WebSocketFrameEncoder newWebSocketEncoder()
Description copied from class:WebSocketClientHandshakerReturns the encoder to use after the handshake is complete.- Specified by:
newWebSocketEncoderin classWebSocketClientHandshaker
-
setForceCloseTimeoutMillis
public WebSocketClientHandshaker00 setForceCloseTimeoutMillis(long forceCloseTimeoutMillis)
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
-
-