import java.io.*; import java.net.*; import com.sun.net.httpserver.*; public class MyHTTPServer { public static void main(String[] args) throws Exception { HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0); server.createContext("/hello", new MyHandler()); server.setExecutor(null); server.start(); System.out.println("Server is listening on port 8080" ); } static class MyHandler implements HttpHandler { public void handle(HttpExchange t) throws IOException { String response = "Hello from MyHTTPServer....."; t.sendResponseHeaders(200, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); } } }
$ java MyHTTPServer & Server is listening on port 8080 $ wget http://localhost:8080/hello -q -O - Hello from MyHTTPServer.....
HttpHandler: .../jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpHandler.html
HttpServer: .../jre/api/net/httpserver/spec/com/sun/net/httpserver/HttpServer.html
Find IP Address
Get All IP Addresses Of A Host
Getting MAC Address
How To Get Http Response Header In Java
My Host Name
My IP Address
Network Interface
Ping IP Address
Port Scanner
Reading The Contents of a Web Page
Reading URLs Protected with HTTP Authentication
Reading and Writing to Sockets
Retrieving Cookies
Sending Email Using JavaMail API
Simple HTTP Server
System Proxy
Who Is Lookup