public WebSocketClient newClient ( final URI url , final WebSocketCallback callback ) { ClientBootstrap bootstrap = new ClientBootstrap ( socketChannelFactory ) ; String protocol = url . getScheme ( ) ; if ( ! protocol . equals ( "ws" ) && ! protocol . equals ( "wss" ) ) { throw new IllegalArgumentException ( "Unsupported protocol: " + protocol ) ; } final WebSocketClientHandler clientHandler = new WebSocketClientHandler ( bootstrap , url , callback ) ; bootstrap . setPipelineFactory ( new ChannelPipelineFactory ( ) { public ChannelPipeline getPipeline ( ) throws Exception { ChannelPipeline pipeline = Channels . pipeline ( ) ; pipeline . addLast ( "decoder" , new HttpResponseDecoder ( ) ) ; pipeline . addLast ( "encoder" , new HttpRequestEncoder ( ) ) ; pipeline . addLast ( "ws-handler" , clientHandler ) ; return pipeline ; } } ) ; return clientHandler ; }
Create a new WebSocket client