Как в Netty остановить сервер?
1 ответ
Что бы остановить сервер.
public class Server {
private Channel channel;
public static void main(String[] args) {
new Server().start();
}
public void start() {
EventLoopGroup producer = new NioEventLoopGroup();
EventLoopGroup consumer = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap().group(producer, consumer)
.channel(NioServerSocketChannel.class)
.childHandler(new Initializer(new NetHandlerPlayServer(this), State.server));
channel = bootstrap.bind(Config.port).sync().channel().closeFuture().sync().channel();
} catch (Exception e) {
e.printStackTrace();
} finally {
producer.shutdownGracefully();
consumer.shutdownGracefully();
channel.disconnect();//Останавливаем сервер.
}
}
public Channel getChannel() {
return channel;
}
}