2011-10-17 06:12:37 +02:00
|
|
|
/*
|
2011-12-09 06:18:34 +01:00
|
|
|
* Copyright 2011 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
|
|
|
*
|
2011-12-09 06:18:34 +01: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.
|
|
|
|
*/
|
2011-12-09 04:38:59 +01:00
|
|
|
package io.netty.example.http.websocketx.autobahn;
|
2011-10-17 06:12:37 +02:00
|
|
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
2011-12-09 04:38:59 +01:00
|
|
|
import io.netty.bootstrap.ServerBootstrap;
|
|
|
|
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
2011-10-17 06:12:37 +02:00
|
|
|
|
|
|
|
/**
|
2011-12-15 06:09:09 +01:00
|
|
|
* A Web Socket echo server for running the <a href="http://www.tavendo.de/autobahn/testsuite.html">autobahn</a> test
|
|
|
|
* suite
|
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-01-14 16:17:10 +01:00
|
|
|
public void run() {
|
2011-12-15 12:25:40 +01:00
|
|
|
// Configure the server.
|
2012-03-28 20:19:39 +02:00
|
|
|
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool()));
|
2011-12-15 06:09:09 +01:00
|
|
|
|
2011-12-15 12:25:40 +01:00
|
|
|
// bootstrap.setOption("child.tcpNoDelay", true);
|
2011-12-15 06:09:09 +01:00
|
|
|
|
2011-12-15 12:25:40 +01:00
|
|
|
// Set up the event pipeline factory.
|
2012-01-14 16:17:10 +01:00
|
|
|
bootstrap.setPipelineFactory(new AutobahnServerPipelineFactory());
|
2011-10-17 06:12:37 +02:00
|
|
|
|
2011-12-15 12:25:40 +01:00
|
|
|
// Bind and start to accept incoming connections.
|
2012-01-14 16:17:10 +01:00
|
|
|
bootstrap.bind(new InetSocketAddress(port));
|
2011-12-15 06:09:09 +01:00
|
|
|
|
2012-01-14 16:17:10 +01:00
|
|
|
System.out.println("Web Socket Server started at port " + port);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
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
|
|
|
}
|