-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleHTTPServer.java
More file actions
29 lines (27 loc) · 904 Bytes
/
SimpleHTTPServer.java
File metadata and controls
29 lines (27 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.util.Date;
public class SimpleHTTPServer
{
public static void main(String[] args) throws IOException
{
final int portNumber = 8080;
final ServerSocket server = new ServerSocket(portNumber);
System.out.println("Listening for connection on port " + portNumber + "....");
while(true)
{
try (final Socket client = server.accept())
{
System.out.println("Client connected");
Date today = new Date();
String httpResponse = "HTTP/1.1 200 OK\r\n\r\n" + today;
client.getOutputStream().write(httpResponse.getBytes("UTF-8"));
client.close();
}
}
}
}