CSE 333 Exercise 11
Due: Monday, November 30 by 11 AM
Rating: 2 (note)
Each exercise this quarter is rated on a integer scale of 1 – 5, inclusive, with 1 being the "least time-consuming" and 5 being the "most time-consuming".
This difficulty scale is meant as a rough guide for you in predicting the amount of time to set aside for each exercise as you balance the work required for 333 with your other obligations. However, it is necessarily imperfect as everyone's set of circumstances and experiences with the exercises differ. If your experience with an exercise does not align with its rating, that is not a reflection of you or your abilities.
Goals
- Adapt server-side networking (TCP) in C/C++.
Problem Description
Write a C++ program that creates a TCP listening socket on a
specified port number.
Once a client connects, the program should read data from the
client socket and write it to stdout until there is no
more data to read from the client (i.e., until
EOF or a socket error occurs).
Once all of the data has been read and written, the program should
close the client socket and the listening socket, and then exit.
Your program should accept the port number as the sole
command-line argument.
An example execution of the completed application mirrors the use
of nc from Exercise 10:
$ ./ex11 5555 > output.bytes
Provided Files
We have provided you with the following four source files, which can be obtained by pulling from your GitLab repo.
SocketUtil.h— Provides the public interface for various server-side networking utility functions. This is similar to the file from Exercise 10, but not the exact same. DO NOT MODIFY.SocketUtil.cc— Contains empty implementations of the utility functions declared in the header file.ex11.cc— Contains an emptymainfunction for the server-side networking program.Makefile— Provided for your convenience in compiling the executableex11.
SocketUtil.cc and
ex11.cc so you should not modify the other
source files.
Implementation Notes
Code Adaptation
Feel free to adapt sample code from lecture and section as part of your solution if it helps, but be sure you understand what your code does when you're done.
User Input
Since you will be reading in user input via command-line arguments, you should make sure your code handles various inputs from the user, which may be in an unexpected format.
Error Handling & Robustness
Remember that the networking methods can fail and should be handled appropriately in these cases. Make sure that you clean up system resources in all possible cases.
Test Suite
We have provided a test suite executable in your GitLab repo that can help you check just the output correctness of your code (i.e., it does not check style or memory). This test suite is purposely opaque and will not reveal what is failing. You should aim to see the following output:
$ ./test_ex11 Test cases purposely not revealed. 0 failed
Testing Notes
Client & Server Setup
To test your program, you must run your server (ex11)
first on the CSE Linux environment such as a specific
attu machine:
$ ./ex11 <port> > output.bytes
Then, on some client machine, which does not need to be
the same machine, send a file to your server using the
ex10 binary (either your own or the released sample
solution).
Assuming the server is running on attu4 and listening
on port 5555:
$ ./ex10 attu4.cs.washington.edu 5555 <filename>
ex11.cc) and binary files
(e.g., ex10).
Validation
Once the file has been transferred, you should confirm that the file was sent correctly. Instead of visually comparing the files in a text editor, which is nearly impossible for a binary file anyway, use existing utilities to make this easier:
- If your input file (the one passed to
ex10) and output file (the one written by the redirect fromex11) are on the same machine (and possibly within the same directory), then you can use thediffutility to check for any discrepancies.For example, if you sent the
ex10binary, redirected the output tooutput.bytes, and they ended up in the same directory, then you can run:$ diff -s ex10 output.bytes
The output will either tell you that the files are identical or give you a summary of the lines that are different. - If your input and output files are on different
machines, you can use the
md5sumutility to produce a checksum digest for both and visually compare them.For example, if you sent the
ex10binary and redirected the output tooutput.bytes, then you would run the following on the server:$ md5sum output.bytes
and the following on the client:$ md5sum ex10
Style Focus
General
For the sake of our autograder, you may not modify
SocketUtil.h, which also means that you should not
modify the function signatures in SocketUtil.cc.
However, feel free to replace the implementations of
WrappedRead() and WrappedWrite() with
yours from Exercise 10.
C/C++ Idioms
To work with the POSIX networking API, we, unfortunately, have to
mix C and C++ idioms in our code.
But you should still try to use C++ idioms whenever possible
(e.g., use cout instead of
printf, use C++ casting).
Submission
Submit the following file(s) by creating an ex11-submit tag in your repo before the assignment deadline. The file(s) should be located in the exact directory listed below, including capitalization:
ex11/ex11.ccex11/SocketUtil.cc
Other files in the ex11/ directory will be ignored, so
you may keep the files unnecessary for submission in there!
For full credit, your code must:
- Compile without errors or warnings on CSE Linux machines
(lab workstations,
attu, or CSE home VM). - Have no runtime errors, memory leaks, or memory errors
(
g++andvalgrind). - Be contained in the files listed above and compile with the provided Makefile.
- Have a comment at the top of your
.ccfiles with your name(s) and CSE or UW email address(es). - Be pretty: the formatting, modularization, variable and
function names, commenting, and so on should be consistent with
class style guidelines.
Additionally, the linter shouldn't have any complaints about your
code (
cpplint.py). - Be robust: your code should deal with hard-to-handle/edge cases and bogus user input (if there are any) gracefully.