Due: Wednesday, August 7th, 2024 by 10:00 am; No
late exercises accepted.
Goals:Write a server that accepts TCP connections from
a client computer and exchange data with it.
Description:
Write the server to go along with ex15. More specifically, write
a C++ program called ex16
that accepts one command line
argument: a port number to listen to.
The program should create a TCP listening socket on the supplied port
number. Once a client connects, the program should read data
from the connected 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.
To test your program, try running it on a specific attu machine,
say attu4.cs.washington.edu
,
and use your ex15
binary to send it a file. For example, on
attu4.cs.washington.edu
, run the following command:
./ex16 5555 > output.bytes
Then, on some client machine, pick a file to send to your server.
For example, this command will send the ex15
binary to the
server (assuming that the server is running on attu4
):
./ex15 attu4.cs.washington.edu 5555 ex15
Once the file has transferred, you should use md5sum to verify that the file was sent correctly. For example, on the server, run this:
md5sum output.bytes
and on the client, run this:
and you should see the same MD5 signature printed out on both ends.md5sum ex15
There are a few requirements on your code:
read
to read from the input client socket.
Pay attention to the possibility that read
might
return EINTR
or EAGAIN
,
and they might read less than you ask for.
We recommend writing some utility functions to deal with this.
Feel free to use fwrite
to write to stdout
if you like.Makefile
so that we can compile your code by
typing make
. Your Makefile
should produce an executable
binary called ex16
and should only recompile and relink files that need to be rebuilt to bring
the program up to date.As with the previous exercise, 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.
As usual, your code must:
Makefile
, as described above, that compiles the code
with the g++
options -Wall -g -std=c++17
cpplint
may be helpful in flagging potential style
problems. (You can ignore cpplint
complaints about
using namespace
directives)
You should submit your exercise to the course Gradescope.