+++ /dev/null
-import java.net.InetAddress;\r
-\r
-// Run the TCPServer on the the port testPort\r
-public class Main {\r
- private static final int DEFAULT_PORT = 10000;\r
- private static final String DEFAULT_ADDRESS = "127.0.0.1";\r
-\r
- /**\r
- * Run the program with arguments to set a custom port and address, see the comments in the code\r
- * @param args\r
- * @throws Exception\r
- */\r
- public static void main(String[] args) throws Exception { \r
- System.setProperty("java.net.preferIPv4Stack", "true"); // force ipv4\r
- int port;\r
- String address;\r
- if (args.length == 0) {\r
- // no arguments: default port and address\r
- port = DEFAULT_PORT;\r
- address = DEFAULT_ADDRESS;\r
- } else if (args.length == 1) {\r
- // one argument for port, default address\r
- port = Integer.valueOf(args[0]);\r
- address = DEFAULT_ADDRESS;\r
- } else if (args.length == 2) {\r
- // two arguments for port and address\r
- // for example, call it like 'java Main 10000 127.0.0.1'\r
- port = Integer.valueOf(args[0]);\r
- address = args[1];\r
- } else {\r
- return;\r
- }\r
- TCPServer server = new TCPServer(port, InetAddress.getByName(address));\r
- \r
- // comment this for the default handler, otherwise the echo server is used\r
- server.setHandlerType("echo");\r
- \r
- server.handleConnections();\r
- }\r
-}\r