u
This commit is contained in:
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());
|
||||
}
|
||||
});
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user