commit | author | age
|
8e2038
|
1 |
package de.uhilger.avdirektor; |
U |
2 |
|
|
3 |
import com.sun.net.httpserver.HttpServer; |
|
4 |
import de.uhilger.avdirektor.handler.PlayHandler; |
|
5 |
import de.uhilger.avdirektor.handler.StopServerHandler; |
|
6 |
import java.io.IOException; |
|
7 |
import java.util.logging.Logger; |
|
8 |
import java.net.InetSocketAddress; |
|
9 |
|
|
10 |
/** |
|
11 |
* |
|
12 |
* @author ulrich |
|
13 |
*/ |
|
14 |
public class Server { |
|
15 |
|
|
16 |
private static final Logger logger = Logger.getLogger(Server.class.getName()); |
|
17 |
|
|
18 |
|
|
19 |
private int port; |
|
20 |
|
|
21 |
public Server(int port) { |
|
22 |
this.port = port; |
|
23 |
} |
|
24 |
|
|
25 |
public void setPort(int port) { |
|
26 |
this.port = port; |
|
27 |
} |
|
28 |
|
|
29 |
public void start() throws IOException { |
|
30 |
logger.info("Server starting on port " + port); |
|
31 |
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
|
32 |
server.createContext("/avd/play", new PlayHandler()); |
|
33 |
server.createContext("/avd/server/stop", new StopServerHandler()); |
|
34 |
server.setExecutor(null); // creates a default executor |
|
35 |
server.start(); |
|
36 |
} |
|
37 |
|
|
38 |
} |