Teaching‎ > ‎CS 4520: Operating Systems‎ > ‎Projects‎ > ‎

Echo Server

Early web servers would fork after accepting a new connection from a client so that each connection was handled by a separate child process.  This way, a client could talk to the server as slowly as it wanted without affecting other connections to the server.  If the server didn't fork, it could get stuck waiting on a misbehaving client, effectively bringing down the whole server.

Instead of writing your own web server (take my other class for that!), you will implement a forking "echo" server from scratch.  Your server should listen for incoming TCP/IP connections and fork to handle each client.  Within each child process, your server should simply echo back anything the client sends to it.

You must use the Berkeley Sockets library (or some binding if you aren't using C) for this project.

To test your server, you can use the 'netcat' a.k.a. 'nc' utility.  You might also try telnet.  You can automate your tests like this:

# Makefile
echo:

test: echo
    ./echo 1100 &    # start echo server on port 1100
    sleep 2   # wait for server to start listening
    nc -q 2 localhost 1100 > out.txt < in.txt
    echo "sent:"
    cat in.txt
    echo "recv'd:"
    cat out.txt
    echo "shutdown" | nc localhost 1100    # server exits when sent "shutdown" message
Comments