1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.netty.testsuite.http2;
18
19 import io.netty.bootstrap.ServerBootstrap;
20 import io.netty.channel.Channel;
21 import io.netty.channel.ChannelOption;
22 import io.netty.channel.EventLoopGroup;
23 import io.netty.channel.nio.NioEventLoopGroup;
24 import io.netty.channel.socket.nio.NioServerSocketChannel;
25 import io.netty.handler.logging.LogLevel;
26 import io.netty.handler.logging.LoggingHandler;
27
28
29
30
31
32 public final class Http2Server {
33
34 private final int port;
35
36 Http2Server(final int port) {
37 this.port = port;
38 }
39
40 void run() throws Exception {
41
42 EventLoopGroup group = new NioEventLoopGroup();
43 try {
44 ServerBootstrap b = new ServerBootstrap();
45 b.option(ChannelOption.SO_BACKLOG, 1024);
46 b.group(group)
47 .channel(NioServerSocketChannel.class)
48 .handler(new LoggingHandler(LogLevel.INFO))
49 .childHandler(new Http2ServerInitializer());
50
51 Channel ch = b.bind(port).sync().channel();
52
53 ch.closeFuture().sync();
54 } finally {
55 group.shutdownGracefully();
56 }
57 }
58
59 public static void main(String[] args) throws Exception {
60 int port;
61 if (args.length > 0) {
62 port = Integer.parseInt(args[0]);
63 } else {
64 port = 9000;
65 }
66 new Http2Server(port).run();
67 }
68 }