Echo Client-Server in C

The goal of these exercises is to gain a thorough understanding of client and server communication over sockets, and refresh your programming skills in C.
  1. Copy echolabsimple.tar from /tmp into directory csc1600:
         cp /tmp/echolab.tar ~/csc1600
  2. Extract the files from your local echolab.tar:
         cd ~/csc1600
         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 tanner. Pass your designated port number N as an argument to the server:
         ./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. Report questions and answers you may generate while experimenting with this code.

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

  7. Modify echoserver.c so that it is multithreaded. For each connection from a client, the server shouwn spawn a thread to service the client, and get back immediately to listening for new incoming requests from clients.

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

    For all exercises below, work with the multithreaded version of your server.

  8. 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):
         server received 4 bytes
  9. 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.
         server received 9 bytes
  10. 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 sockets.