This commit is contained in:
oneao committed 2025-10-13 17:32:02 +08:00
1 parent a6c5e70f85
commit 2598098876
8 files changed
+646 -45

No files matched your search

@@ -8,6 +8,8 @@ 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.codec.http.cors.CorsConfig;
import io.netty.handler.codec.http.cors.CorsHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.timeout.IdleStateHandler;
@@ -53,18 +55,11 @@ public class ImServer {
protected void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
// ===== HTTP 协议支持 =====
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(65536));
pipeline.addLast(new ChunkedWriteHandler());
// ===== 心跳检测 =====
pipeline.addLast(new IdleStateHandler(60, 0, 0, TimeUnit.SECONDS));
// ===== WebSocket 协议支持 =====
pipeline.addLast(new CorsHandler(CorsConfig.withAnyOrigin().build()));
pipeline.addLast(new WebSocketServerProtocolHandler(websocketPath, null, true, 65536));
// ===== 自定义消息处理 =====
pipeline.addLast(new ImWebSocketHandler());
}
});