2011-10-17 06:12:37 +02:00
|
|
|
/*
|
2012-06-04 22:31:44 +02:00
|
|
|
* Copyright 2012 The Netty Project
|
2011-10-17 06:12:37 +02:00
|
|
|
*
|
2011-12-09 06:18:34 +01:00
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
2011-10-17 06:12:37 +02:00
|
|
|
*
|
2012-06-04 22:31:44 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-10-17 06:12:37 +02:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
2011-12-09 06:18:34 +01:00
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
2011-10-17 06:12:37 +02:00
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2017-02-20 14:06:48 +01:00
|
|
|
package io.netty.testsuite.autobahn;
|
2011-10-17 06:12:37 +02:00
|
|
|
|
2011-12-09 04:38:59 +01:00
|
|
|
import io.netty.bootstrap.ServerBootstrap;
|
2013-11-15 12:00:33 +01:00
|
|
|
import io.netty.buffer.PooledByteBufAllocator;
|
2012-05-30 01:41:26 +02:00
|
|
|
import io.netty.channel.ChannelFuture;
|
2013-11-15 12:00:33 +01:00
|
|
|
import io.netty.channel.ChannelOption;
|
2013-04-03 09:15:33 +02:00
|
|
|
import io.netty.channel.EventLoopGroup;
|
2013-02-01 10:32:27 +01:00
|
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
2012-05-30 01:41:26 +02:00
|
|
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
2011-10-17 06:12:37 +02:00
|
|
|
|
|
|
|
/**
|
2016-03-16 18:49:18 +01:00
|
|
|
* A Web Socket echo server for running the
|
|
|
|
* <a href="http://autobahn.ws/testsuite/">autobahn test suite</a>
|
2011-10-17 06:12:37 +02:00
|
|
|
*/
|
2012-01-14 16:17:10 +01:00
|
|
|
public class AutobahnServer {
|
|
|
|
|
|
|
|
private final int port;
|
|
|
|
|
|
|
|
public AutobahnServer(int port) {
|
|
|
|
this.port = port;
|
|
|
|
}
|
2011-12-15 06:09:09 +01:00
|
|
|
|
2012-05-30 01:41:26 +02:00
|
|
|
public void run() throws Exception {
|
2014-04-24 14:13:19 +02:00
|
|
|
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
|
|
|
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
2012-05-30 01:41:26 +02:00
|
|
|
try {
|
2013-04-03 09:15:33 +02:00
|
|
|
ServerBootstrap b = new ServerBootstrap();
|
2014-04-24 14:13:19 +02:00
|
|
|
b.group(bossGroup, workerGroup)
|
2012-09-11 09:34:51 +02:00
|
|
|
.channel(NioServerSocketChannel.class)
|
2013-11-15 12:00:33 +01:00
|
|
|
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
|
2012-06-03 10:00:16 +02:00
|
|
|
.childHandler(new AutobahnServerInitializer());
|
2011-12-15 06:09:09 +01:00
|
|
|
|
2013-01-30 12:06:40 +01:00
|
|
|
ChannelFuture f = b.bind(port).sync();
|
2012-05-30 01:41:26 +02:00
|
|
|
System.out.println("Web Socket Server started at port " + port);
|
|
|
|
f.channel().closeFuture().sync();
|
|
|
|
} finally {
|
2014-04-24 14:13:19 +02:00
|
|
|
bossGroup.shutdownGracefully();
|
|
|
|
workerGroup.shutdownGracefully();
|
2012-05-30 01:41:26 +02:00
|
|
|
}
|
2012-01-14 16:17:10 +01:00
|
|
|
}
|
|
|
|
|
2012-05-30 01:41:26 +02:00
|
|
|
public static void main(String[] args) throws Exception {
|
2012-01-14 16:17:10 +01:00
|
|
|
int port;
|
|
|
|
if (args.length > 0) {
|
|
|
|
port = Integer.parseInt(args[0]);
|
|
|
|
} else {
|
|
|
|
port = 9000;
|
|
|
|
}
|
|
|
|
new AutobahnServer(port).run();
|
2011-12-15 12:25:40 +01:00
|
|
|
}
|
2011-10-17 06:12:37 +02:00
|
|
|
}
|