Commit fabdbcfd authored by AfirSraftGarrier's avatar AfirSraftGarrier

格式并加些打印

parent 88980bb9
......@@ -8,8 +8,6 @@ import org.springframework.stereotype.Component;
@Component
@Slf4j
public class ForwardClient {
private TcpClient client = null;
private ForwardChannelInitializer channelInitializer;
......@@ -17,7 +15,6 @@ public class ForwardClient {
ForwardClientHandler handler;
public ForwardClient() {
}
public void startTcp(String host, int port, String appId) {
......@@ -31,5 +28,4 @@ public class ForwardClient {
client = new TcpClient(host, port, channelInitializer, listener);
client.start();
}
}
......@@ -10,43 +10,36 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TcpClient {
private int port;
private String host;
private BaseChannelInitializer channelInitializer;
private BaseConnectionListener connectionListener;
private int port;
private String host;
private BaseChannelInitializer channelInitializer;
private BaseConnectionListener connectionListener;
public TcpClient(String host, int port,BaseChannelInitializer channelInitializer,BaseConnectionListener connectionListener) {
this.host = host;
this.port = port;
this.channelInitializer = channelInitializer;
this.connectionListener = connectionListener;
}
public TcpClient(String host, int port, BaseChannelInitializer channelInitializer, BaseConnectionListener connectionListener) {
this.host = host;
this.port = port;
this.channelInitializer = channelInitializer;
this.connectionListener = connectionListener;
}
public void start() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.group(eventLoopGroup)
.remoteAddress(host, port)
.handler(channelInitializer);
ChannelFuture future = bootstrap.connect(host, port);
future.addListener(connectionListener);
} catch (Exception e) {
// TODO Auto-generated catch block
log.error("Tcp客户端异常,端口:{}",port);
}
public void start() {
Thread thread = new Thread(() -> {
try {
EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.group(eventLoopGroup)
.remoteAddress(host, port)
.handler(channelInitializer);
ChannelFuture future = bootstrap.connect(host, port);
future.addListener(connectionListener);
} catch (Exception e) {
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