| | |
| | | import io.netty.channel.socket.nio.NioServerSocketChannel; |
| | | import io.netty.handler.codec.http.HttpServerCodec; |
| | | import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * webscoket 服务 |
| | |
| | | * @author:xp |
| | | * @date:2024/4/11 17:47 |
| | | */ |
| | | @Slf4j |
| | | public class WebsocketServer { |
| | | |
| | | public static void runWebsocket() throws Exception { |
| | |
| | | |
| | | // 绑定服务器到指定的端口,并且等待绑定操作完成。 |
| | | ChannelFuture f = b.bind(8084).sync(); |
| | | |
| | | log.info("websocket启动成功"); |
| | | // 等待服务器的通道关闭。 |
| | | f.channel().closeFuture().sync(); |
| | | } finally { |
| | | workerGroup.shutdownGracefully(); |
| | | bossGroup.shutdownGracefully(); |
| | | log.info("websocket关闭"); |
| | | } |
| | | } |
| | | |