From 7863a228b54722d7b1b42f9e39e2ee115a97aee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 22 Feb 2016 15:35:29 +0100 Subject: WIP --- build.gradle | 9 ++++++ server/build.gradle | 27 ++++++++++++++++ server/src/ch/asynk/rustanddust/server/Server.java | 37 ++++++++++++++++++++++ settings.gradle | 2 +- 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 server/build.gradle create mode 100644 server/src/ch/asynk/rustanddust/server/Server.java diff --git a/build.gradle b/build.gradle index bd67a0a..24ada65 100644 --- a/build.gradle +++ b/build.gradle @@ -77,6 +77,15 @@ project(":core") { } } +project(":server") { + apply plugin: "java" + + + dependencies { + compile project(":core") + } +} + task ctags(type: Exec) { executable "ctags" args "-R", "--language-force=java", "-f.tags", "core/src/" diff --git a/server/build.gradle b/server/build.gradle new file mode 100644 index 0000000..d2c6481 --- /dev/null +++ b/server/build.gradle @@ -0,0 +1,27 @@ +apply plugin: "java" + +sourceCompatibility = 1.7 +sourceSets.main.java.srcDirs = [ "src/" ] + +project.ext.mainClassName = "ch.asynk.rustanddust.server.Server" + +task run(dependsOn: classes, type: JavaExec) { + main = project.mainClassName + classpath = sourceSets.main.runtimeClasspath + standardInput = System.in + /* workingDir = project.assetsDir */ + ignoreExitValue = true +} + +task dist(type: Jar) { + from files(sourceSets.main.output.classesDir) + from files(sourceSets.main.output.resourcesDir) + from {configurations.compile.collect {zipTree(it)}} + /* from files(project.assetsDir); */ + + manifest { + attributes 'Main-Class': project.mainClassName + } +} + +dist.dependsOn classes 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."); + } + } +} diff --git a/settings.gradle b/settings.gradle index 13eeafe..d729d0d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include 'desktop', 'android', 'core', 'assets' +include 'desktop', 'android', 'core', 'assets', 'server' -- cgit v1.1-2-g2b99