CS 145A Lab 1 (due: Oct 24th)
Connection
Tasks for Lab 1
- Write a program ("server"") that can act as a server
- Write a program ("tcpclient") that can send TCP packets
- Write a program ("udpclient") that can send UDP packets
Server
The parameter format of the server is: "server <port 1> <port2>",
where <port 1> is the port number for TCP service, <port 2> is the port
number for UDP service.
The server should implement the following functions:
- accept TCP connections in <port 1> (for TCP service)
- accept UDP packets in <port 2> (for UDP service)
- "Talk" with the clients. That is, the server returns the same contents as
the client sends to it, in the same protocol. (If the client is UDP, server returns
the message in UDP. If the client is TCP, server returns the message in TCP).
For TCP Connections:
- If a
TCP client does not send anything in 10 seconds,
the server should actively disconnect the connection. (Note that UDP does not maintain a
stream connection.)
- The server should be able to "talk" with 3 different
clients at the same time. The server should not keep more than 3 clients at
the same time.
Submission:
Please submit your codes in "server.c" or "server.cpp",
and your documents in "server.txt"
Tips:
- Read the lecture slides and reference books to see the necessary steps.
- Useful functions: socket, bind, listen, accept, close, read, write (for
socket programming); select (for multiplexing); fork (for child-process)
- See the "man" page for these functions, then maybe you can see
other useful ones.
- You can use "telnet" to test the server.
TCP Client
The parameter of the TCP client is "tcpclient <host> <port>
<message> <time> ", where <host> is the server's IP; <port> is the server's port for TCP, <message> is the message
you want to send, <time> is the waiting time for the client before disconnection.
<message> contains English characters only.
The tcpclient should implement the following function:
- send <message> to the server with TCP, wait for <time> seconds, then disconnect.
Submission:
Please submit your codes in "tcpclient.c" or "tcpclient.cpp",
and your documents in "tcpclient.txt"
UDP client
The parameter of the UDP client is "udpclient <host> <port> <message>",
where <host> is the server's IP; <port> is the server's port
for UDP, <message> is the message you want to send. <message> contains
English characters only.
The udpclient should implement the following function:
- send <message> to the server with UDP.
Submission:
Please submit your codes in "udpclient.c" or "udpclient.cpp",
and your documents in "udpclient.txt"
Requirements of Documentation
Please add enough comments in your codes (enough to show your understanding
of the work).
Please use the documents (*.txt) to describe:
- How to use the program? How to compile it? How to run it?
- Your design
- Your testing data. Please test your codes thoroughly before submission.
- The problems or bugs your found in the process of design, implementation and testing; and your solutions
- Any other comments you think useful.
Suggestions
- Write the codes in a graceful style.
- Use "Makefile" to speed up your testing.
- Use "man"
- Think thoroughly (or discuss with TA about your design) before you type in the
codes.
Grading
- Correctness (70%)
- Documentation and comments (20%)
- Program style (10%)