Commit 11ef370f authored by AfirSraftGarrier's avatar AfirSraftGarrier

测试

parent 14de6597
...@@ -24,22 +24,23 @@ public class TcpClient { ...@@ -24,22 +24,23 @@ public class TcpClient {
public void start() { public void start() {
Thread thread = new Thread(() -> { Thread thread = new Thread(() -> {
try { try {
EventLoopGroup eventLoopGroup = new NioEventLoopGroup(); EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap(); Bootstrap bootstrap = new Bootstrap();
bootstrap bootstrap
.channel(NioSocketChannel.class) .channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.SO_KEEPALIVE, true)
.group(eventLoopGroup) .group(eventLoopGroup)
.remoteAddress(host, port) .remoteAddress(host, port)
.handler(channelInitializer); .handler(channelInitializer);
ChannelFuture future = bootstrap.connect(host, port); ChannelFuture future = bootstrap.connect(host, port);
future.addListener(connectionListener); future.addListener(connectionListener);
} catch (Exception e) { } catch (Exception e) {
log.error("Tcp客户端异常,端口:{}", port); e.printStackTrace();
} log.error("Tcp客户端异常,端口:{}", port);
}); }
});
thread.start(); thread.start();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment