Administrator
4 days ago cb78ad5f3aa9436cf32ae74f07dd1a5d18b8f046
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cc.mrbird.febs.common.websocket;
 
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
 
@Component
public class WebSocketServer {
 
//    @Value("${netty.websocket.port:9102}")
//    private int port;
//
//    @Autowired
//    private ServerBootstrap serverBootstrap;
//
//    @Autowired
//    private EventLoopGroup bossGroup;
//
//    @Autowired
//    private EventLoopGroup workerGroup;
//
//    private ChannelFuture channelFuture;
//
//    @PostConstruct
//    public void start() throws InterruptedException {
//        channelFuture = serverBootstrap.bind(port).sync();
//        System.out.println("Netty WebSocket服务器启动在端口:" + port);
//    }
//
//    @PreDestroy
//    public void stop() {
//        if (channelFuture != null) {
//            channelFuture.channel().close();
//        }
//        bossGroup.shutdownGracefully();
//        workerGroup.shutdownGracefully();
//        System.out.println("Netty WebSocket服务器已停止");
//    }
}