guoyujie
2 天以前 c4b9a339caff12e95f61c3d5dc950aafcc8c566c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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));
    }
}