In this homework, you will use socket programming to develop a proxy server that helps a client program download a file. The server program will be running on a remote server. The client program will connect to the server program, and send a command with the target file's URL. The proxy server will fetch the file and transfer it to the client program. see image.
You need to develop two programs: (1) HW1Server.java and (2) HW1Client.java.
HW1Server.java
1.The server program should be launched as
java HW1Server portNumber
where the argument portNumber specifies the port of the proxy server.
2.The server program has to support multiple concurrent clients. (refer to MultiThreadEchoServer example)
3.Once a client command is received, the server program needs to identify the target file (host and file name), and then creates another socket to the remote server following HTTP protocol. The request line and one header line are required. For example,
GET /index.html HTTP/1.1
Host: example.com
4.The server program will get a HTTP response from the remote server including a status line, some header lines, and the data. The server program needs to transfer the data back to the client.
HW1Client.java
1.The client program should be launched as
java HW1Client host portNumber
where the two argument specify the host and port of the server program.
2.After the connection is established, the user can type in a command with the target file's URL that will be sent to the server, e.g.,
GET example.com/index.html
3.Next, the client will start to receive data from the proxy server. Your client program needs to show the downloading progress (any form is OK).
1.Run your server program in a server host,
$java HW1Server 9999
2.Run your client program in another host or the same host, e.g.,
$java HW1Client localhost 9999
3.Type in a command from the client's program, e.g.,
GET www.espn.com/index.html
4.Confirm the file is downloaded at the client's side, e.g.,
$cat index.html