-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicWebServer.java
More file actions
53 lines (40 loc) · 1.48 KB
/
BasicWebServer.java
File metadata and controls
53 lines (40 loc) · 1.48 KB
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
49
50
51
52
53
import java.io.*;
import java.net.*;
import java.util.*;
import serverCache.ServerCacheSingleton;
class BasicWebServer{
public static int serverPort = 6789;
//public static String WWW_ROOT = "/home/httpd/html/zoo/classes/cs433/";
public static String WWW_ROOT = util.WS_ROOT;
public static void main(String args[]) throws Exception {
// see if we do not use default server port
// if (args.length >= 1)
// serverPort = Integer.parseInt(args[0]);
//
// // see if we want a different root
// if (args.length >= 2)
// WWW_ROOT = args[1];
properties prop = new properties();
if (args.length >= 2){
prop.config(args[1]);
serverPort = prop.getServerPort();
}
// create server socket
ServerSocket listenSocket = new ServerSocket(serverPort);
System.out.println("server listening at: " + listenSocket);
System.out.println("server www root: " + WWW_ROOT);
ServerCacheSingleton.init(4096);
while (true) {
try {
// take a ready connection from the accepted queue
Socket connectionSocket = listenSocket.accept();
WebRequestHandler wrh =
new WebRequestHandler(connectionSocket,prop.getNameMap());
// System.out.println("\nReceive request from " + connectionSocket);
wrh.run();
} catch (Exception e)
{
}
} // end of while (true)
} // end of main
} // end of class WebServer