Question: 1 Introduction Programming Assignment 1 Introduction to Socket Programming Berners-Lee and his team are credited for inventing the original Hyper Text Transfer Protocol (HTTP) along
1 Introduction
Programming Assignment 1 Introduction to Socket Programming
Berners-Lee and his team are credited for inventing the original Hyper Text Transfer Protocol (HTTP) along with Hyper Text Markup Language (HTML) and the associated technology for a web server and a text-based web browser. The first version of the protocol had only one method, namely GET, which would request a page from a server. The response from the server was always an HTML page. What youre about to do is to reinvent the wheel on the motivation of getting a deep understanding of how HTTP works!
In this assignment, you will use sockets to implement a simple web client that communicates with a web server using a restricted subset of HTTP. The main objective of this assignment is to give you hands-on experience with UNIX sockets.
2 Multi-threaded Web Server 2.1 Introduction and Background
Please refer to the lectures slides for the format and the use of HTTP.
2.2 Specifications
Your web server should accept incoming connection requests. It should then look for the GET request and pick out the name of the requested file. Note that a GET request from a real WWW client may have several lines of optional information following the GET. These optional lines, though, will be terminated by a blank line (i.e., a line containing zero or more spaces, terminated by a (carriage return then newline characters). Your server should first print out the received command as well as any optional lines following it (and preceding the empty line).
The server should then respond with the line, this is a very simple version of the real HTTP reply message:
HTTP/1.0 200 OK then in case of GET command only: {data, data, ...., data} followed by a blank line (i.e., a string with only blanks, terminated by a ). After finishing the transmission, the server should close the socket created by the accept() function and wait to accept a new connection request. If the document is not found (in case of GET), the server should respond with(as would a real http server) :
HTTP/1.0 404 Not Found
2.3 Server Side Pesudo Code
while true: do Listen for connections Accept new connection from incoming client and delegate it to worker thread/process Parse HTTP/1.0 request and determine the command (i.e. GET) Determine if target file exists (in case of GET) and return error otherwise Transmit contents of file (reads from the file and writes on the socket) (in case of GET) Close the connection
end while
2.4 Notes
You should handle the both commands GET (to get file from the server). No validation (on requests) required. However, you should write the described format of the command.
There are different types of HTTP status codes, youre only required to handle 404 and 200.
You will want to become familiar with the Socket programming in Java( check out Oracle Socket Tutorial:
https://docs.oracle.com/javase/tutorial/networking/sockets/. You are supposed to handle HTML, TXT and images.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
