Top Description Fields Constructors Methods
io.netty.handler.codec.http.websocketx

public Class WebSocketClientHandshaker00

extends WebSocketClientHandshaker
Class Inheritance
Imports
io.netty.buffer.ByteBuf, .Unpooled, io.netty.handler.codec.http.DefaultFullHttpRequest, .FullHttpRequest, .FullHttpResponse, .HttpHeaderNames, .HttpHeaderValues, .HttpHeaders, .HttpMethod, .HttpResponseStatus, .HttpVersion, io.netty.util.internal.PlatformDependent, java.net.URI, java.nio.ByteBuffer

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

Modifier and TypeField and Description
private ByteBuf
Inherited from io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker:
customHeadersDEFAULT_FORCE_CLOSE_TIMEOUT_MILLISgenerateOriginHeader

Constructor Summary

AccessConstructor and Description
public
WebSocketClientHandshaker00(URI
URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
webSocketURL
,
WebSocketVersion
Version of web socket specification to use to connect to the server
version
,
String
Sub protocol request sent to the server.
subprotocol
,
HttpHeaders
Map of custom headers to add to the client request
customHeaders
,
int
Maximum length of a frame's payload
maxFramePayloadLength
)

Creates a new instance with the specified destination WebSocket location and version to initiate.

public
WebSocketClientHandshaker00(URI
URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
webSocketURL
,
WebSocketVersion
Version of web socket specification to use to connect to the server
version
,
String
Sub protocol request sent to the server.
subprotocol
,
HttpHeaders
Map of custom headers to add to the client request
customHeaders
,
int
Maximum length of a frame's payload
maxFramePayloadLength
,
long
Close the connection if it was not closed by the server after timeout specified
forceCloseTimeoutMillis
)

Creates a new instance with the specified destination WebSocket location and version to initiate.

pack-priv
WebSocketClientHandshaker00(URI
URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
webSocketURL
,
WebSocketVersion
Version of web socket specification to use to connect to the server
version
,
String
Sub protocol request sent to the server.
subprotocol
,
HttpHeaders
Map of custom headers to add to the client request
customHeaders
,
int
Maximum length of a frame's payload
maxFramePayloadLength
,
long
Close the connection if it was not closed by the server after timeout specified
forceCloseTimeoutMillis
,
boolean
Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP
absoluteUpgradeUrl
)

Creates a new instance with the specified destination WebSocket location and version to initiate.

pack-priv
WebSocketClientHandshaker00(URI
URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
webSocketURL
,
WebSocketVersion
Version of web socket specification to use to connect to the server
version
,
String
Sub protocol request sent to the server.
subprotocol
,
HttpHeaders
Map of custom headers to add to the client request
customHeaders
,
int
Maximum length of a frame's payload
maxFramePayloadLength
,
long
Close the connection if it was not closed by the server after timeout specified
forceCloseTimeoutMillis
,
boolean
Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP
absoluteUpgradeUrl
,
boolean
Allows to generate the `Origin` header value for handshake request according to the given webSocketURL
generateOriginHeader
)

Creates a new instance with the specified destination WebSocket location and version to initiate.

Method Summary

Modifier and TypeMethod and Description
private static String
private static String
insertSpaces(String key, int spaces)

protected FullHttpRequest
newHandshakeRequest()

Implements abstract io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.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
protected WebSocketFrameDecoder
newWebsocketDecoder()

Implements abstract io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.newWebsocketDecoder.

Returns the decoder to use after handshake is complete.
protected WebSocketFrameEncoder
newWebSocketEncoder()

Implements abstract io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.newWebSocketEncoder.

Returns the encoder to use after the handshake is complete.
public WebSocketClientHandshaker00
setForceCloseTimeoutMillis(long
Close the connection if it was not closed by the server after timeout specified
forceCloseTimeoutMillis
)

Overrides io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.setForceCloseTimeoutMillis.

Sets timeout to close the connection if it was not closed by the server.
protected void
verify(FullHttpResponse
HTTP response returned from the server for the request sent by beginOpeningHandshake00().
response
)

Implements abstract io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.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-
Inherited from io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker:
actualSubprotocolclosecloseclosecloseexpectedSubprotocolfinishHandshakeforceCloseTimeoutMillishandshakehandshakeisForceCloseCompleteisHandshakeCompletemaxFramePayloadLengthprocessHandshakeprocessHandshakeupgradeUrluriversionwebsocketHostValuewebsocketOriginValue

Field Detail

expectedChallengeResponseBytesback to summary
private ByteBuf expectedChallengeResponseBytes

Constructor Detail

WebSocketClientHandshaker00back to summary
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:URI

URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.

version:WebSocketVersion

Version of web socket specification to use to connect to the server

subprotocol:String

Sub protocol request sent to the server.

customHeaders:HttpHeaders

Map of custom headers to add to the client request

maxFramePayloadLength:int

Maximum length of a frame's payload

WebSocketClientHandshaker00back to summary
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:URI

URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.

version:WebSocketVersion

Version of web socket specification to use to connect to the server

subprotocol:String

Sub protocol request sent to the server.

customHeaders:HttpHeaders

Map of custom headers to add to the client request

maxFramePayloadLength:int

Maximum length of a frame's payload

forceCloseTimeoutMillis:long

Close the connection if it was not closed by the server after timeout specified

WebSocketClientHandshaker00back to summary
pack-priv WebSocketClientHandshaker00(URI webSocketURL, WebSocketVersion version, 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:URI

URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.

version:WebSocketVersion

Version of web socket specification to use to connect to the server

subprotocol:String

Sub protocol request sent to the server.

customHeaders:HttpHeaders

Map of custom headers to add to the client request

maxFramePayloadLength:int

Maximum length of a frame's payload

forceCloseTimeoutMillis:long

Close the connection if it was not closed by the server after timeout specified

absoluteUpgradeUrl:boolean

Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP

WebSocketClientHandshaker00back to summary
pack-priv WebSocketClientHandshaker00(URI webSocketURL, WebSocketVersion version, String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl, boolean generateOriginHeader)

Creates a new instance with the specified destination WebSocket location and version to initiate.

Parameters
webSocketURL:URI

URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.

version:WebSocketVersion

Version of web socket specification to use to connect to the server

subprotocol:String

Sub protocol request sent to the server.

customHeaders:HttpHeaders

Map of custom headers to add to the client request

maxFramePayloadLength:int

Maximum length of a frame's payload

forceCloseTimeoutMillis:long

Close the connection if it was not closed by the server after timeout specified

absoluteUpgradeUrl:boolean

Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP

generateOriginHeader:boolean

Allows to generate the `Origin` header value for handshake request according to the given webSocketURL

Method Detail

insertRandomCharactersback to summary
private static String insertRandomCharacters(String key)
insertSpacesback to summary
private static String insertSpaces(String key, int spaces)
newHandshakeRequestback to summary
protected FullHttpRequest newHandshakeRequest()

Implements abstract io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.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
Annotations
@Override
newWebsocketDecoderback to summary
protected WebSocketFrameDecoder newWebsocketDecoder()

Implements abstract io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.newWebsocketDecoder.

Doc from io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.newWebsocketDecoder.

Returns the decoder to use after handshake is complete.

Annotations
@Override
newWebSocketEncoderback to summary
protected WebSocketFrameEncoder newWebSocketEncoder()

Implements abstract io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.newWebSocketEncoder.

Doc from io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.newWebSocketEncoder.

Returns the encoder to use after the handshake is complete.

Annotations
@Override
setForceCloseTimeoutMillisback to summary
public WebSocketClientHandshaker00 setForceCloseTimeoutMillis(long forceCloseTimeoutMillis)

Overrides io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.setForceCloseTimeoutMillis.

Doc from io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.setForceCloseTimeoutMillis.

Sets timeout to close the connection if it was not closed by the server.

Parameters
forceCloseTimeoutMillis:long

Close the connection if it was not closed by the server after timeout specified

Annotations
@Override
verifyback to summary
protected void verify(FullHttpResponse response)

Implements abstract io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.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-
Parameters
response:FullHttpResponse

HTTP response returned from the server for the request sent by beginOpeningHandshake00().

Annotations
@Override