diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-02-22 15:35:29 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-02-22 15:35:29 +0100 |
commit | 7863a228b54722d7b1b42f9e39e2ee115a97aee5 (patch) | |
tree | 01576c5e63d15786001d56fcfb3ee76e8082694d /server/src/ch/asynk/rustanddust | |
parent | 3134a588789cde591daa6065cf5e5db4b3c82523 (diff) | |
download | RustAndDust-server.zip RustAndDust-server.tar.gz |
WIPserver
Diffstat (limited to 'server/src/ch/asynk/rustanddust')
-rw-r--r-- | server/src/ch/asynk/rustanddust/server/Server.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/server/src/ch/asynk/rustanddust/server/Server.java b/server/src/ch/asynk/rustanddust/server/Server.java new file mode 100644 index 0000000..4a2000c --- /dev/null +++ b/server/src/ch/asynk/rustanddust/server/Server.java @@ -0,0 +1,37 @@ +package ch.asynk.rustanddust.server; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; + +public class Server +{ + + public static void main(String[] args) throws Exception + { + HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0); + server.createContext("/test", new MyHandler()); + server.setExecutor(null); + server.start(); + // System.exit(0); + } + + static class MyHandler implements HttpHandler + { + @Override + public void handle(HttpExchange t) throws IOException + { + System.err.print("answering ..."); + String response = "This is the response"; + t.sendResponseHeaders(200, response.length()); + OutputStream os = t.getResponseBody(); + os.write(response.getBytes()); + os.close(); + System.err.print("done."); + } + } +} |