@Override
protected void initChannel(SocketChannel ch) throws Exception {
//流水线管理通道中的处理程序(Handler),用来处理业务
//http编解码器
ch.pipeline().addLast(new HttpServerCodec());
ch.pipeline().addLast(new ObjectEncoder());
//以块的方式来写的处理器
ch.pipeline().addLast(new ChunkedWriteHandler());
/*
* 说明
* 1、http数据在传输过程中是分段的,HttpObjectAggregator可以将多个段聚合
* 2、当浏览器发送大量数据时,就会发送多次http请求
*/
ch.pipeline().addLast(new HttpObjectAggregator(8192));
/*
说明:
1、对应webSocket,它的数据是以帧(frame)的形式传递
2、浏览器请求时 ws://localhost:58080/xxx 表示请求的uri
3、核心功能是将http协议升级为ws协议,保持长连接
*/
ch.pipeline().addLast(new WebSocketServerProtocolHandler(webSocketPath, WEBSOCKET_PROTOCOL, true, 65536 * 10));
//自定义的handler,处理业务逻辑
ch.pipeline().addLast(webSocketHandler);
}
});
最终还是改了写法,使用springboot去整合websocket,没有使用netty
有没有那位大佬能为我解惑一下