package com.snowcattle.game.common.socket.server; 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 io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; /** * Created by jiangwenping on 17/1/22. */ public class EchoServer { public static final int Port = 9999; public static void main(String[] args) { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try{ ServerBootstrap serverBootstrap = new ServerBootstrap(); serverBootstrap = serverBootstrap.group(bossGroup, bossGroup); serverBootstrap.channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 1024) .option(ChannelOption.TCP_NODELAY, true) .handler(new LoggingHandler(LogLevel.INFO)) // .childHandler(new ServerChannelInitializer()); // .childHandler(new StringServerChannelInitializer()); // .childHandler(new ProtoServerChannelInitializer()); .childHandler(new NetMessageServerChannleInitializer()); ChannelFuture serverChannelFuture = serverBootstrap.bind(Port).sync(); serverChannelFuture.channel().closeFuture().sync(); }catch (Exception e){ }finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } } }