-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWebServer.java
More file actions
48 lines (35 loc) · 1017 Bytes
/
WebServer.java
File metadata and controls
48 lines (35 loc) · 1017 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class WebServer {
ServerSocket server_socket;
public int PORT = 6969;
public static void main(String[] args) throws Exception {
WebServer web_server = new WebServer();
web_server.runServer();
}
public void runServer() throws Exception {
System.out.println("Multi-Threaded Web Server has now Started");
System.out.println("Enter \"localhost:" + PORT + "/abm523.html\" in your web browser.");
server_socket = new ServerSocket(PORT);
processHTTPRequest();
}
public void processHTTPRequest() {
while(true) {
System.out.println("\nConnection established on port: " + PORT);
Socket socket = null;
try {
socket = server_socket.accept();
} catch (IOException e) {
e.printStackTrace();
}
Connection connection = null;
try {
connection = new Connection(socket);
} catch (Exception e) {
e.printStackTrace();
}
connection.start();
}
}
}