Echo Client-Server in C

These are a few simple examples meant to refresh your knowledge of client and server communication over TCP sockets.

  1. Dowload echoapp.tar (or echoapp.zip, if working in Windows) and extract the files into a Unix (or Windows) directory. You should see the following files:

    echoserver.c  C code for a sequential echo server
    echoservert.c  C code for a multi-threaded 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
    readmeThis file

  2. Build the echoserver, echoservert and echoclient executables by typing in make at the shell prompt. (In Windows, use your own environment to compile the source files.)

  3. Test the client and sequential server on tanner. Pick a 5-digit integer number N no greater than 64000 and pass it as a port argument to the server:
         ./echoserver N

    Using telnet: Open a separate window on tanner and invoke telnet by passing it the host name and the port number for the echo server:

         telnet localhost  N
    Now anything you type into the client window will be sent over the connection and echoed back to you by the server.

    Using the echo client: Open a separate window on tanner and invoke the echo client by passing it the host name and the port number for the server:

         ./echoclient localhost N
    Now anything you type into the client window will be sent over the connection and echoed back to you by the server.

  4. 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.

  5. The multithreaded version echoservert.c spawns a thread for each connection from a client, then gets 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.