The system consists of one server hosting one web application. Any number of clients can access the server to request resources (GET). The server processes the requests and generates responses back to the client.
Connection Management: The web application uses HTTP on TCP. The server can accept multiple simultaneous TCP requests from multiple clients. The TCP connection management is multi-threaded, meaning that the server has a listening socket that accepts connection requests. Upon receiving a connection request, a connection socket will be opened using a threaded process. The connections are persistent, meaning that only the client can close the connection.
Processing HTTP Requests: The server is always listening to all open connection sockets. Once an HTTP request is received, it joins a queue. This queue is simply a data structure that saves all received requests in the order in which they arrive. The server takes one HTTP requests from the head of the queue, processes it, generates a response, sends the response through the appropriate connection socket, then after all this is done it takes the following HTTP request from the queue.
The HTTP requests are generated by the client. They should consist of 4 lines:
-Method URL Version\n -Host\n -Accepted format\n -Connection The method can only be “GET”. GET is used to retrieve resources from the server, In addition, the “Host” in the HTTP request is the name of your web application, which you choose yourself. The “accepted format” header specifies the format in which you want the object (txt, JPEG, etc.). The server should not send back a response unless it has the requested object in the requested format. Finally, the “connection” header specifies what the client wants the server to do with the TCP connection. This value should be “keep-alive” for all HTTP reqeusts, except for the last one requested by the client. In the last one only, it should be “close”. Once the client generates an HTTP request with “Connection: Close”, the server will close the connection directly after sending the HTTP resposne. The client will also close the connection after receiveing the HTTP response.
Generating the HTTP Response: After the HTTP request is parsed, the server will start the process of generating the response. The HTTP response should have 4 lines, plus the requested object (if found): Status Version Timestamp Format Connection The status can either be:
- 200 OK: if the HTTP request has been processed successfully (the object was found in the requested format).
- 404 Not Found: this should be inserted if the object has not been found in the requested format. The “timestamp” header is the date and time when the response was created. In addition, the header “format” is the format of the object in the response. Finally, “connection” can either be keep-alive or close, depending on what was specified in the HTTP request.