@Override
public void start() {
b.group(workGroup)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_KEEPALIVE, true)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("SdkServerDecoder", new SdkClientDecoder(12))
.addLast("SdkServerEncoder", new SdkClientEncoder())
.addLast("SdkClientHandler", new SdkClientHandler());
}
});
try {
cf = b.connect(GlobalConfig.DEFAULT_HOST, GlobalConfig.SDKS_PORT).sync();
cf.channel().closeFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
logger.error("client channel close", channelFuture.cause());
shutdown();
}
});
InetSocketAddress address = (InetSocketAddress) cf.channel().remoteAddress();
logger.info("SdkClient start success, host is {}, port is {}", address.getHostName(),
address.getPort());
} catch (InterruptedException e) {
logger.error("SdkClient start error", e);
shutdown(); //关闭并释放资源
}
}
SdkClient.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:DistributedID-SDK
作者:
评论列表
文章目录