Last active
August 30, 2017 05:00
-
-
Save Soontao/7f7fd035a5a2b54169843865cfd18a22 to your computer and use it in GitHub Desktop.
Http Server Sample with java 8 lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.net.InetSocketAddress; | |
import com.sun.net.httpserver.HttpServer; | |
public class HttpServerSample { | |
public static void main(String[] args) throws IOException { | |
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0); | |
server.createContext("/", exchange -> { | |
String body = "hello http server"; | |
exchange.sendResponseHeaders(200, body.length()); | |
exchange.getResponseBody().write(body.getBytes()); | |
exchange.getRequestBody().close(); | |
}); | |
server.start(); | |
System.out.println("server started at :8080"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment