|
@@ -11,7 +11,9 @@ import io.netty.channel.group.ChannelGroup;
|
|
import io.netty.channel.group.DefaultChannelGroup;
|
|
import io.netty.channel.group.DefaultChannelGroup;
|
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
|
import io.netty.util.concurrent.GlobalEventExecutor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
+@Slf4j
|
|
public class WebSocketChannelPool {
|
|
public class WebSocketChannelPool {
|
|
public static ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
|
public static ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
|
// 收到信息后,群发消息
|
|
// 收到信息后,群发消息
|
|
@@ -25,10 +27,13 @@ public class WebSocketChannelPool {
|
|
Channel channel = id2Channel.get(id);
|
|
Channel channel = id2Channel.get(id);
|
|
if (channel != null) {
|
|
if (channel != null) {
|
|
String sendString = JSONObject.toJSONString(content, SerializerFeature.WriteMapNullValue);
|
|
String sendString = JSONObject.toJSONString(content, SerializerFeature.WriteMapNullValue);
|
|
|
|
+ // log.info("WebSocket send " + id + "\t" + channel.localAddress().toString() + "\t" + channel.remoteAddress().toString() + "\t"
|
|
|
|
+ // + sendString);
|
|
|
|
+ log.info("WebSocket send " + channel.remoteAddress().toString() + "\t" + sendString);
|
|
channel.writeAndFlush(new TextWebSocketFrame(sendString));
|
|
channel.writeAndFlush(new TextWebSocketFrame(sendString));
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.error(e.getMessage(), e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|