Commit fabdbcfd authored by AfirSraftGarrier's avatar AfirSraftGarrier

格式并加些打印

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