Echo Client-Server in C

The goal of these exercises is to gain some experience with clients and servers communicating over Internet sockets.
  1. Copy echolab.tar from the /tmp directory on tanner into your csc2405 directory:
         cp /tmp/echolab.tar ~/csc2405
  2. Extract the files from your local echolab.tar:
         cd ~/csc2405
         tar xvf echolab.tar
    
    This will cause a number of files to be unpacked in your directory echolab:
    echoserver.c  C code for a sequential echo server
    echoclient.cC code for an echo client
    nethelp.cFile containing helper functions
    nethelp.h Header file for functions defined in nethelp.c
    MakefileCompiles and links together nethelp.c and a source file

  3. Build the echoserver and echoclient executables by typing in make at the shell prompt.

  4. Test the client and server on a Unix machine of your choice (tanner, degas, rodin). Pass your designated port number N as an argument to the server:
         ./echoserver N
    Open a separate window to test the server with telnet first. You'll need to pass to the client the name of the machine on which the server runs -- for example, if working on degas, type in
         telnet degas  N
    Next test both the echo client and echo server and by having them communicate with each other. Restart your server, then in a different terminal type in
         ./echoclient degas N
    Now anything you type into the client window will be sent over the connection and echoed back to you by the server.

  5. Try to understand what each step of the client and server code does.

  6. Modify echoclient.c so that the client quits when the user types in the string quit or exit.

  7. Modify echoserver.c to have the server reverse the string prior to sending it back to the client (with the exception of the '\n' at the end):
         123
         server received 4 bytes
         321
    
  8. Modify echoserver.c to have the server create a new thread each time it receives and accepts a connection request from a client (one thread per client). The new thread will provide service to the client, while the server gets back immediately to listening for new incoming requests from other clients.

    Note that the server will have to pass to the thread the file descriptor for the connection returned by the accept system call, so that the thread can use it in its communication with the client.

    To test your multithreaded server, open two client windows and have the clients talk simultaneously to the server.