Homework 3
Due Wednesday 10/12 @ 11:59pm
Problem 1: Basic Socket Programming
Write a program to send an ASCII message over the network, wait
for a response, print out the response and exit. The message should consist of your student
ID number, sent in a UDP datagram to csgateway.clarku.edu at port 1928. A process will be
running on that host to service your incoming messages and transmit a message back to the port
of origin. Submit a listing of your (hopefully) short program, the message you transmitted, and
the response you received.
This warmup exercise is designed to give you some background you will need for the first programming project. The essential facts about socket programming you will need are in Sections
2.7 and 2.8 of the text, and posted on the course schedule.
Send me an email if your program gets no response from the server. I may need to restart it.
Test your program by running it on csgateway.clarku.edu itself. This will avoid any network security concerns that might reject your connection.
Problem 2: Basic Web Sever
In this assigment, you will develop a simple web server that is capable of processing a single request. Specifically, your web server will
- Create a connection socket when contacted by a client (browser)
- Receive the HTTP request from this connection
- Parse the request to dtermine the specific file being requested (you only need to handle GET requests)
- Get the file from the server's file system (assume a subdirectory that you specify and put some test files into)
- Create/send an HTTP response message consisting of header line(s) and the requested file.
- If anything goes wrong (e.g. file not found), send a properly formatted 404 Not Found error message.
You should start with one of the sample programs and modify it to work as above. Test your program by placing some HTML files into your subdirectory and requesting them from a web browser. You can also test your server with netcat (nc), curl, or wget.
Optional: Implement the "If-Modified-Since" option on the HTTP GET request, and the "Last-Modified" header entry on the HTTP reponse headers.
See
RFC2616 and search within the page for those two header strings.
Notes:
- Test from your own computer: http://localhost:12345/hello.html
- Pick a port number between 2000-65000.
- A basic Python solution might be only about 25 lines of code. My solution has 63 lines with comments and whitespace.
- Use any programming language - or try it in multiple languages.
- Feel free to ask how to do certain things (e.g. read files) on the Facebook group.
- Please attempt to write this yourself. It's not very hard and will be a good warmup for the larger programming projects to come. If you just find a ready-to-use solution on the web you won't learn anything.
What to Submit
Submit your two programs as well as screenshots verifying that they work properly on Moodle. I may ask you to demo your programs to me.
Grading Criteria
Part 1: 30%
Part 2: 70%
Academic Honesty and Collaboration
Cooperation is recommended in understanding programming
concepts and system features. But the actual solution of the
assignments including all programming must be your individual
work. For example, copying without attribution any part of someone
else's program is plagiarism, even if you have modified the code.
The University takes acts of cheating and plagiarism very
seriously.