| | |
| | | import io.netty.channel.socket.nio.NioServerSocketChannel; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | |
| | | */ |
| | | private EventLoopGroup work = new NioEventLoopGroup(); |
| | | |
| | | @Value("netty.port") |
| | | private Integer port; |
| | | |
| | | /** |
| | | * 启动Netty Server |
| | | * |
| | |
| | | // 指定Channel |
| | | .channel(NioServerSocketChannel.class) |
| | | //使用指定的端口设置套接字地址 |
| | | .localAddress(new InetSocketAddress(10001)) |
| | | .localAddress(new InetSocketAddress(port)) |
| | | |
| | | //服务端可连接队列数,对应TCP/IP协议listen函数中backlog参数 |
| | | .option(ChannelOption.SO_BACKLOG, 1024) |