diff options
Diffstat (limited to 'server/src')
-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."); + } + } +} |