廖井涛
2025-04-09 c04f3e10d8ba26d6e4d568727ee97110d8a0fddc
north-glass-erp/src/main/java/com/example/erp/tools/netty/MyChannelHandlerPool.java
New file
@@ -0,0 +1,26 @@
package com.example.erp.tools.netty;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.springframework.context.annotation.Bean;
/**
 * MyChannelHandlerPool
 * 通道组池,管理所有websocket连接
 */
public class MyChannelHandlerPool {
    public MyChannelHandlerPool(){}
    public static ChannelGroup channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    public void sendMsg(String message){
        channelGroup.writeAndFlush(new TextWebSocketFrame(message));
    }
}