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 bossGroup = new NioEventLoopGroup(1);
40 EventLoopGroup workerGroup = new NioEventLoopGroup();
41 try {
42 ServerBootstrap b = new ServerBootstrap();
43 b.group(bossGroup, workerGroup)
44 .channel(NioServerSocketChannel.class)
45 .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
46 .childHandler(new AutobahnServerInitializer());
47
48 ChannelFuture f = b.bind(port).sync();
49 System.out.println("Web Socket Server started at port " + port);
50 f.channel().closeFuture().sync();
51 } finally {
52 bossGroup.shutdownGracefully();
53 workerGroup.shutdownGracefully();
54 }
55 }
56
57 public static void main(String[] args) throws Exception {
58 int port;
59 if (args.length > 0) {
60 port = Integer.parseInt(args[0]);
61 } else {
62 port = 9000;
63 }
64 new AutobahnServer(port).run();
65 }
66 }