Echo Client-Server in C

The goal of this exercise is to gain a thorough understanding of the Robust I/O Interface implemented in csapp.c.
  1. Copy echolab.tar from /tmp into directory csc2405:
         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
    csapp.cFile containing helper functions and error handling wrappers
    csapp.h Header file for functions defined in csapp.c
    MakefileCompiles and links together csapp.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 tanner. Pick a random 5-digit integer N no greater than 64000 and pass it to the server as an argument:
         ./echoserver N
    Open a separate window on tanner to test the server with telnet first:
         telnet tanner  N
    and with the echo client second:
         ./echoclient tanner 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. Pay close attention to the use of the Robust I/O (Rio) interface. Report questions and answers you may generate while experimenting with this code.

  6. 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
    
  7. Modify echoserver.c to wait for two text lines from the client, concatenate them together (use strcat; if necessary, use the manual pages - man strcat - to learn about strcat) and send the result back to the client.
         123
         4567
         server received 9 bytes
         1234567
    
  8. Modify the code for the client and/or server code to provide some additional functionality - anything that would help you better understand the use of the Socket and RIO interface functions.