From de31e91aa2f38a717f2d4640a3197580ec1807a7 Mon Sep 17 00:00:00 2001
From: 钟日健 <5689795+arsn@user.noreply.gitee.com>
Date: Thu, 19 May 2022 11:23:51 +0800
Subject: [PATCH] 关闭websckot
---
src/main/java/org/springblade/modules/webscoket/WebSocketServer.java | 118 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 59 insertions(+), 59 deletions(-)
diff --git a/src/main/java/org/springblade/modules/webscoket/WebSocketServer.java b/src/main/java/org/springblade/modules/webscoket/WebSocketServer.java
index a47840a..f3aa0fb 100644
--- a/src/main/java/org/springblade/modules/webscoket/WebSocketServer.java
+++ b/src/main/java/org/springblade/modules/webscoket/WebSocketServer.java
@@ -1,59 +1,59 @@
-package org.springblade.modules.webscoket;
-import io.netty.bootstrap.ServerBootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.channel.socket.nio.NioServerSocketChannel;
-import io.netty.handler.codec.http.HttpObjectAggregator;
-import io.netty.handler.codec.http.HttpServerCodec;
-import io.netty.handler.logging.LogLevel;
-import io.netty.handler.logging.LoggingHandler;
-import io.netty.handler.stream.ChunkedWriteHandler;
-
-public class WebSocketServer {
- private int port = 9034;
-
- public WebSocketServer(int port) {
- bind(port);
- }
-
- public void bind(int port) {
- Thread thread = new Thread(new Runnable() {
- @Override
- public void run() {
- EventLoopGroup bossGroup = new NioEventLoopGroup();
- EventLoopGroup workerGroup = new NioEventLoopGroup();
- try {
- ServerBootstrap serverBootstrap = new ServerBootstrap();
- serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
- .handler(new LoggingHandler(LogLevel.INFO))
- //保持连接
- .childOption(ChannelOption.SO_KEEPALIVE, true)
- .childHandler(new ChannelInitializer<SocketChannel>() {
- @Override
- protected void initChannel(SocketChannel ch) {
-// ch.pipeline().addLast("logging",new LoggingHandler("DEBUG"));//设置log监听器,并且日志级别为debug,方便观察运行流程
- ch.pipeline().addLast("http-codec", new HttpServerCodec());//设置解码器
- ch.pipeline().addLast("aggregator", new HttpObjectAggregator(65536));//聚合器,使用websocket会用到
- ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler());//用于大数据的分区传输
- ch.pipeline().addLast("handler", new WebSocketHandler());//自定义的业务handler
- }
- });
-
- ChannelFuture channelFuture = serverBootstrap.bind(port).sync();
- System.out.println("WebSocketServer启动成功");
- channelFuture.channel().closeFuture().sync();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- bossGroup.shutdownGracefully();
- workerGroup.shutdownGracefully();
- }
- }
- });
- thread.start();
- }
-}
+//package org.springblade.modules.webscoket;
+//import io.netty.bootstrap.ServerBootstrap;
+//import io.netty.channel.ChannelFuture;
+//import io.netty.channel.ChannelInitializer;
+//import io.netty.channel.ChannelOption;
+//import io.netty.channel.EventLoopGroup;
+//import io.netty.channel.nio.NioEventLoopGroup;
+//import io.netty.channel.socket.SocketChannel;
+//import io.netty.channel.socket.nio.NioServerSocketChannel;
+//import io.netty.handler.codec.http.HttpObjectAggregator;
+//import io.netty.handler.codec.http.HttpServerCodec;
+//import io.netty.handler.logging.LogLevel;
+//import io.netty.handler.logging.LoggingHandler;
+//import io.netty.handler.stream.ChunkedWriteHandler;
+//
+//public class WebSocketServer {
+// private int port = 9034;
+//
+// public WebSocketServer(int port) {
+// bind(port);
+// }
+//
+// public void bind(int port) {
+// Thread thread = new Thread(new Runnable() {
+// @Override
+// public void run() {
+// EventLoopGroup bossGroup = new NioEventLoopGroup();
+// EventLoopGroup workerGroup = new NioEventLoopGroup();
+// try {
+// ServerBootstrap serverBootstrap = new ServerBootstrap();
+// serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
+// .handler(new LoggingHandler(LogLevel.INFO))
+// //保持连接
+// .childOption(ChannelOption.SO_KEEPALIVE, true)
+// .childHandler(new ChannelInitializer<SocketChannel>() {
+// @Override
+// protected void initChannel(SocketChannel ch) {
+//// ch.pipeline().addLast("logging",new LoggingHandler("DEBUG"));//设置log监听器,并且日志级别为debug,方便观察运行流程
+// ch.pipeline().addLast("http-codec", new HttpServerCodec());//设置解码器
+// ch.pipeline().addLast("aggregator", new HttpObjectAggregator(65536));//聚合器,使用websocket会用到
+// ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler());//用于大数据的分区传输
+// ch.pipeline().addLast("handler", new WebSocketHandler());//自定义的业务handler
+// }
+// });
+//
+// ChannelFuture channelFuture = serverBootstrap.bind(port).sync();
+// System.out.println("WebSocketServer启动成功");
+// channelFuture.channel().closeFuture().sync();
+// } catch (Exception e) {
+// e.printStackTrace();
+// } finally {
+// bossGroup.shutdownGracefully();
+// workerGroup.shutdownGracefully();
+// }
+// }
+// });
+// thread.start();
+// }
+//}
--
Gitblit v1.9.3