COMPSCI 356 Computer Network Architectures: Lab 0 An Echo Server
Introduction
This assignment is a warm-up for the following four labs. You are required to implement a simple echo server using the ANSI C socket API. An echo server can listen on a specific TCP port, and wait for a client to connect. After a TCP connection is established between the echo server and a client, the client can send arbitrary messages to the server and the server will echo back the same message to the client.
Your task is to implement the echo server. We provide the source code of the echo client for you.
Environment
You are required to finish all the labs in Ubuntu environment. We have set up an Ubuntu 12.04 virtual machine image for you. You can download it here. We will test your code in this virtual machine. Currently we have tested this virtual machine image in the following platforms:
- Windows 7 - VirutalBox 4.3.6
- Windows 7 - VMware WorkStation 10.0.0
- Mac OS X - VirtualBox 4.3.6
Starter Code
We provide the skeleton code of the echo server (not implemented) and the client (implemented) code in one C program. The source code contains a main function which is the entry point of the program, a client function, which implements the client, and a server function, which you should modify to implement the server. You should submit the source code and make sure that it can compile.
We also provide you the binary code that includes full functions of both the client and server for you to test your echo server. You can execute the binary code in either the client mode or the server mode with the following command (suppose the file name of the binary code is "myprog"):
myprog s <port>
It will start an echo server and listen on the TCP port whose port number is <port>. For example, "myprog s 9999" will start an echo server and listen on port 9999.
myprog c <port> <address>
It will start a client to connect to an echo server whose IP address is <address> and port is <port>. For example, "myprog c 9999 127.0.0.1" will start a client and try to connect to port 9999 in you own machine. Then you can type any message and press "Enter" to send to the server that is running at your machine's port 9999. The client will print the message received from the server on the screen. You can disconnect the client from the server by terminating the process of the client.
Requirements
- Your server can listen on an arbitrary TCP port.
- Your server can wait for a client to connect. You can assume that only one client is served at a time.
- After connected to a client, your server can receive a message no longer than 512 bytes from the client, and echo back the same message, until the client closes the TCP connection.
- After the previous client closes its TCP connection, your server could wait for another client to connect.