2 Commits

Author SHA1 Message Date
wujiawei
32eaace9c1 [fix] 异常打印 2025-06-17 13:51:42 +08:00
wujiawei
21136284c7 [fix] 优化绑定下一个通道问题 2025-06-17 13:50:37 +08:00
2 changed files with 10 additions and 9 deletions

View File

@@ -63,6 +63,8 @@ public class NettySocksServerProxyClientTransferHandler extends SimpleChannelInb
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
log.error(cause.getMessage());
super.exceptionCaught(ctx, cause);
}
}

View File

@@ -128,6 +128,14 @@ public class NettySocksServerProxyClientRealSocket {
Channel transferChannel = futureListener.channel();
if (futureListener.isSuccess()) {
log.info("服务端代理客户端socks客户端连接服务端传输通道成功");
// 绑定下一个通道
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, realChannel);
ChannelAttributeKeyUtils.buildNextChannel(realChannel, transferChannel);
// 绑定客户端真实通信通道
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
// 开始读取数据
realChannel.config().setOption(ChannelOption.AUTO_READ, true);
// 通知服务端访客连接成功
NettyProxyMsg nettyProxyMsg = new NettyProxyMsg();
@@ -137,15 +145,6 @@ public class NettySocksServerProxyClientRealSocket {
nettyProxyMsg.setTargetPort(targetPort);
nettyProxyMsg.setType(ProxyMessageType.SOCKS_REPORT_SERVER_PROXY_CLIENT_CONNECTION_SUCCESS_);
transferChannel.writeAndFlush(nettyProxyMsg);
ChannelAttributeKeyUtils.buildNextChannel(transferChannel, realChannel);
ChannelAttributeKeyUtils.buildNextChannel(realChannel, transferChannel);
// 绑定客户端真实通信通道
ChannelAttributeKeyUtils.buildVisitorId(transferChannel, visitorId);
ChannelAttributeKeyUtils.buildClientId(transferChannel, clientId);
} else {
log.info("无法连接到服务端....");
eventLoopGroup.schedule(() -> {