1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.testsuite.autobahn;
17
18 import io.netty.bootstrap.ServerBootstrap;
19 import io.netty.buffer.PooledByteBufAllocator;
20 import io.netty.channel.ChannelFuture;
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
26
27
28
29
30 public class AutobahnServer {
31
32 private final int port;
33
34 public AutobahnServer(int port) {
35 this.port = port;
36 }
37
38 public void run() throws Exception {
39 EventLoopGroup group = new NioEventLoopGroup();
40 try {
41 ServerBootstrap b = new ServerBootstrap();
42 b.group(group)
43 .channel(NioServerSocketChannel.class)
44 .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
45 .childHandler(new AutobahnServerInitializer());
46
47 ChannelFuture f = b.bind(port).sync();
48 System.out.println("Web Socket Server started at port " + port);
49 f.channel().closeFuture().sync();
50 } finally {
51 group.shutdownGracefully();
52 }
53 }
54
55 public static void main(String[] args) throws Exception {
56 int port;
57 if (args.length > 0) {
58 port = Integer.parseInt(args[0]);
59 } else {
60 port = 9000;
61 }
62 new AutobahnServer(port).run();
63 }
64 }