}
@Override
<<<<<<< HEAD
public WebSocketClient start() {
final byte[] outboundMaskingKey = new byte[]{randomByte(), randomByte(), randomByte(), randomByte()};
bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();
if (ssl) {
if (sslFactory == null) {
throw new WebbitException("You need to call setupSsl first");
}
SSLContext sslContext = sslFactory.getClientContext();
SSLEngine sslEngine = sslContext.createSSLEngine();
sslEngine.setUseClientMode(true);
pipeline.addLast("ssl", new SslHandler(sslEngine));
}
pipeline.addLast("decoder", new HttpResponseDecoder());
pipeline.addLast("encoder", new HttpRequestEncoder());
pipeline.addLast("inflater", new HttpContentDecompressor());
pipeline.addLast("handshakeHandler", new HandshakeChannelHandler(outboundMaskingKey));
return pipeline;
}
=======
public Future start() {
final FutureTask future = new FutureTask(new Callable() {
@Override
public WebSocket call() throws Exception {
final byte[] outboundMaskingKey = new byte[]{randomByte(), randomByte(), randomByte(), randomByte()};
bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();
pipeline.addLast("decoder", new HttpResponseDecoder());
pipeline.addLast("encoder", new HttpRequestEncoder());
pipeline.addLast("inflater", new HttpContentDecompressor());
pipeline.addLast("handshakeHandler", new HandshakeChannelHandler(outboundMaskingKey));
return pipeline;
}
});
ChannelFuture future = bootstrap.connect(remoteAddress);
channel = future.awaitUninterruptibly().getChannel();
if (!future.isSuccess()) {
close();
} else {
ChannelFuture requestFuture = channel.write(request);
requestFuture.awaitUninterruptibly();
}
return WebSocketClient.this;
};
>>>>>>> a794d75448eaa6e49f46e0b5061909e00989fb99
});
executor.execute(future); |