socket通讯调整
This commit is contained in:
@@ -73,13 +73,10 @@ public class NettyClient {
|
|||||||
channelFuture.addListener((ChannelFutureListener) ch -> {
|
channelFuture.addListener((ChannelFutureListener) ch -> {
|
||||||
if (!ch.isSuccess()) {
|
if (!ch.isSuccess()) {
|
||||||
System.out.println("链接服务端失败...");
|
System.out.println("链接服务端失败...");
|
||||||
|
// 连接失败时关闭 group
|
||||||
|
group.shutdownGracefully();
|
||||||
} else {
|
} else {
|
||||||
System.out.println("链接服务端成功...");
|
System.out.println("链接服务端成功...");
|
||||||
System.out.println("客户端向服务端发送消息:" + port + msg);
|
|
||||||
channelFuture.channel().writeAndFlush(msg + "\n").sync();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (handler instanceof NettySourceClientHandler) {
|
if (handler instanceof NettySourceClientHandler) {
|
||||||
NioEventLoopGroup groupByUserId = SocketManager.getGroupByUserId(param.getUserPageId() + source);
|
NioEventLoopGroup groupByUserId = SocketManager.getGroupByUserId(param.getUserPageId() + source);
|
||||||
if(ObjectUtil.isNotNull(groupByUserId)){
|
if(ObjectUtil.isNotNull(groupByUserId)){
|
||||||
@@ -94,8 +91,10 @@ public class NettyClient {
|
|||||||
SocketManager.addGroup(param.getUserPageId() + dev, group);
|
SocketManager.addGroup(param.getUserPageId() + dev, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("客户端向服务端发送消息:" + port + msg);
|
||||||
|
channelFuture.channel().writeAndFlush(msg + "\n");
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("连接socket服务端发送异常............" + e.getMessage());
|
System.out.println("连接socket服务端发送异常............" + e.getMessage());
|
||||||
group.shutdownGracefully();
|
group.shutdownGracefully();
|
||||||
|
|||||||
Reference in New Issue
Block a user