-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyHttpServer.java
31 lines (28 loc) · 965 Bytes
/
MyHttpServer.java
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
package mp1;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.HashMap;
import request.Handler;
import request.Util;
import java.util.LinkedList;
import java.util.List;
/**
*this class runs a httpServer
*/
public class MyHttpServer {
public static void main(String[] args) throws IOException {
//number of the port to access
final String PORT = System.getenv().getOrDefault("SERVER_PORT", "8080");;
ServerSocket serverSocket = new ServerSocket(Integer.valueOf(PORT));
//threads running
List<Integer> idRegistry = new LinkedList<>();
int id = 0;
//hashMap with the files stored in the server
HashMap<String, String> contentDirectory = Util.getContentDirectory("directory");
while (true) {
Handler taskSolver = new Handler(serverSocket.accept(), id, contentDirectory, idRegistry);
id++;
taskSolver.start();
}
}
}