|
- package com.ssjl.zhaobiao.guizhou.netty;
- //
- //import io.netty.bootstrap.ServerBootstrap;
- //import io.netty.channel.ChannelFuture;
- //import io.netty.channel.ChannelOption;
- //import io.netty.channel.EventLoopGroup;
- //import io.netty.channel.nio.NioEventLoopGroup;
- //import io.netty.channel.socket.nio.NioServerSocketChannel;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Component;
-
- import javax.annotation.PostConstruct;
- import java.net.InetSocketAddress;
-
- @Slf4j
- @Component
- public class NettyServer {
- @Value("${netty.host}")
- private String host;
- @Value("${netty.port}")
- private int port;
-
- //
- // public void start(){
- // EventLoopGroup bossGroup = new NioEventLoopGroup(1);
- // EventLoopGroup workGroup = new NioEventLoopGroup(1);
- // ServerBootstrap bootstrap = new ServerBootstrap()
- // .group(bossGroup, workGroup)
- // .channel(NioServerSocketChannel.class)
- // .childHandler(new NettyServerInitializer())
- //// .localAddress(new InetSocketAddress(port))
- // .localAddress(host, port)
- // .option(ChannelOption.SO_BACKLOG, 128)
- // .childOption(ChannelOption.SO_KEEPALIVE, true);
- // try {
- // ChannelFuture future = bootstrap.bind().sync();
- //// ChannelFuture future = bootstrap.bind();
- // if(future.isSuccess()){
- // log.info("server start success");
- // }else{
- // log.info("server start error");
- // }
- //
- //// future.channel().closeFuture().sync();
- // }catch (Exception e){
- // e.printStackTrace();
- // }
- // finally {
- //// bossGroup.shutdownGracefully();
- //// workGroup.shutdownGracefully();
- // }
- // }
- }
|