|
|
@@ -3,9 +3,9 @@ package com.yhlxj.netty.websocket.starter.netty;
|
|
|
import com.yhlxj.netty.websocket.starter.WebsocketProperties;
|
|
|
import io.netty.bootstrap.ServerBootstrap;
|
|
|
import io.netty.channel.*;
|
|
|
-import io.netty.channel.nio.NioEventLoopGroup;
|
|
|
-import io.netty.channel.socket.nio.NioServerSocketChannel;
|
|
|
-import io.netty.channel.socket.nio.NioSocketChannel;
|
|
|
+import io.netty.channel.epoll.EpollEventLoopGroup;
|
|
|
+import io.netty.channel.epoll.EpollServerSocketChannel;
|
|
|
+import io.netty.channel.epoll.EpollSocketChannel;
|
|
|
import io.netty.handler.codec.http.HttpObjectAggregator;
|
|
|
import io.netty.handler.codec.http.HttpServerCodec;
|
|
|
import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator;
|
|
|
@@ -27,14 +27,14 @@ public class NettyWebsocketServer {
|
|
|
}
|
|
|
|
|
|
public void start() throws InterruptedException {
|
|
|
- NioEventLoopGroup boss = new NioEventLoopGroup(websocketProperties.getBossThreadNums());
|
|
|
- NioEventLoopGroup worker = new NioEventLoopGroup(websocketProperties.getWorkerThreadNums());
|
|
|
+ EpollEventLoopGroup boss = new EpollEventLoopGroup(websocketProperties.getBossThreadNums());
|
|
|
+ EpollEventLoopGroup worker = new EpollEventLoopGroup(websocketProperties.getWorkerThreadNums());
|
|
|
ServerBootstrap bootstrap = new ServerBootstrap();
|
|
|
bootstrap.group(boss,worker)
|
|
|
- .channel(NioServerSocketChannel.class)
|
|
|
- .childHandler(new ChannelInitializer<NioSocketChannel>() {
|
|
|
+ .channel(EpollServerSocketChannel.class)
|
|
|
+ .childHandler(new ChannelInitializer<EpollSocketChannel>() {
|
|
|
@Override
|
|
|
- protected void initChannel(NioSocketChannel channel) {
|
|
|
+ protected void initChannel(EpollSocketChannel channel) {
|
|
|
ChannelPipeline pipeline = channel.pipeline();
|
|
|
pipeline.addLast(new HttpServerCodec())
|
|
|
.addLast(new HttpObjectAggregator(websocketProperties.getMaxContentLength()))
|