public ClientHandshakeFuture handshake ( ) { final DefaultClientHandshakeFuture handshakeFuture = new DefaultClientHandshakeFuture ( ) ; try { URI uri = new URI ( url ) ; String scheme = uri . getScheme ( ) ; if ( ! Constants . WS_SCHEME . equalsIgnoreCase ( scheme ) && ! Constants . WSS_SCHEME . equalsIgnoreCase ( scheme ) ) { LOG . error ( "Only WS(S) is supported." ) ; throw new URISyntaxException ( url , "WebSocket client supports only WS(S) scheme" ) ; } final String host = uri . getHost ( ) == null ? "127.0.0.1" : uri . getHost ( ) ; final int port = getPort ( uri ) ; final boolean ssl = Constants . WSS_SCHEME . equalsIgnoreCase ( scheme ) ; WebSocketClientHandshaker webSocketHandshaker = WebSocketClientHandshakerFactory . newHandshaker ( uri , WebSocketVersion . V13 , subProtocols , true , headers , maxFrameSize ) ; MessageQueueHandler messageQueueHandler = new MessageQueueHandler ( ) ; clientHandshakeHandler = new WebSocketClientHandshakeHandler ( webSocketHandshaker , handshakeFuture , messageQueueHandler , ssl , autoRead , url , handshakeFuture ) ; Bootstrap clientBootstrap = initClientBootstrap ( host , port , handshakeFuture ) ; clientBootstrap . connect ( uri . getHost ( ) , port ) . sync ( ) ; } catch ( Exception throwable ) { handleHandshakeError ( handshakeFuture , throwable ) ; } return handshakeFuture ; }
Handle the handshake with the server .