@Override
public void connect() throws InterruptedException{
// Connect with V13 (RFC 6455 aka HyBi-17). You can change it to V08 or V00.
// If you change it to V00, ping is not supported and remember to change
// HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
handler =
new WebSocketClientHandler(
WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, true, new DefaultHttpHeaders(),this.getMaxPayload()));
//make sure the handler has a refernce to this object.
handler.setClient(this);
Bootstrap clientBoot = new Bootstrap();
clientBoot.group(group)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
SSLEngine sslEngine=null;
if(AbstractClient.this.isEncrypted()){
if(sslContext == null){
sslEngine = new SSLFactory().createClientSslCtx(Config.getInstance()).newEngine(ch.alloc(), uri.getHost(),uri.getPort());
}else{
sslEngine = sslContext.newEngine(ch.alloc(),uri.getHost(),uri.getPort());
}
sslEngine.setEnabledProtocols(Const.TLS_PROTOCOLS);
sslEngine.setUseClientMode(true);
p.addLast(new SslHandler(sslEngine));
}
p.addLast( new HttpClientCodec());
p.addLast(new HttpObjectAggregator(8192));
if(AbstractClient.this.isCompress()){
p.addLast(WebSocketClientCompressionHandler.INSTANCE);
}
p.addLast(handler);
}
});
this.ch = clientBoot.connect(uri.getHost(), uri.getPort()).sync().channel();
handler.handshakeFuture().sync();
}
AbstractClient.java 文件源码
java
阅读 21
收藏 0
点赞 0
评论 0
项目:xockets.io
作者:
评论列表
文章目录