IUNP Programming Assignment 1
Should be done by Monday
This programming assignment is meant to prepare you for assignment
2. By implementing the program specified in this assignment, you would get
familiar with the Unix network programming API. The assignment is to be done
in groups of size 2 at the most. (I would prefer you doing this alone.) You
are responsible for finding your partner. Please carefully read the example
codes I've given, and build your program on top of the examples. Doing so
is not absolutely required, but it will save you a lot of time.
The program is to be written in C or C++ under a Unix platform
such as Linux, SunOS, Solaris, or FreeBSD. The catch is that, you have to
make sure your program compiles under Solaris. There should not be any problem
working under different Unix platforms, if you use the Makefile as in the
examples I've provided.
The program to be written is called thechoer (or your
favourite name), whose features are described below.
- thechoer takes as arguments a tcp port and a udp port to which it
will listen to incoming connection requests and incoming udp packets, respectively:
thechoer <tcp-port> <udp-port>
- thechoer must be able to handle up to 7 outgoing tcp connections
at the same time. Feel free to increase your limit to be more than 7. We shall
only test your program for up to 7 outgoing connections. By "outgoing
connections", we mean the connections in which the process under consideration
is on the client side.
- thechoer operates somewhat like a shell. It keeps taking user's commands,
at the same time watches incoming connection requests and data packets. When
appropriate, thechoer prints out diagnostic information to stdout and
goes back to the prompt mode to accept user's inputs.
- below is a description of all commands thechoer is supposed to handle,
along with the description of associated actions :
- info: print out its IP address, host name, TCP port, UDP port.
For example:
IP address hostname upd port tcp port
192.168.0.3 (funny.cse.buffalo.edu) 4892 43444
- connect <ip-address> <tcp-port>: try to establish a
tcp connection to <ip-address> at port <tcp-port>. For example
connect 192.168.0.3 99999
the two sides then report that the connection is indeed established.
- show: show all existing outgoing tcp connections in the following
format:
conn. ID | IP | hostname | local port | remote port
---------------------------------------------------------------------------------
1 | 192.168.0.1 | abc.cse.buffalo.edu | 1234 | 1235
2 | 192.168.0.2 | def.cse.buffalo.edu | 1453 | 98234
3 | 192.168.0.3 | ghi.cse.buffalo.edu | 1233 | 09823
4 | 192.168.0.4 | xyz.cse.buffalo.edu | 1235 | 0823
- send <conn-id> <message>: send to the connection whose
id is <conn-id> the <message> that follows. For example,
send 3 Oh! This assignment is a piece of cake.
- sendto <ip-address> <udp-port> <message>: send
<message> as a udp datagram to <ip-address> at <udp-poprt>.
- disconnect <conn-id>: disconnect the tcp connection whose
id is <conn-id>.
- the rest of the user's inputs should be reported as "unknown command"
- for each message thechoer sends out, the process (which is an instance
of thechoer) attaches is process ID (PID) along. Feel free to use any
packet format you want to encapsulate the PID and the message. Make sure that,
if you send the PID as an integer, then you must take care of the little-endian/big-endian
issue.
- up on receiving a TCP connection request from someone, thechoer spawns
a child process to handle the new request. It prints out something like
got Conn. request from 192.168.0.2, child 19534 handling it.
- The child process just echoes whatever it receives and quits when the connection
is closed by the client. Recall that the child process has to attach its PID
to the message it is echoing. Moreover, it reports the following for each
message that it aches:
echoing "message"
to: IP = <ip-address>
type = tcp
PID = <my-pid>
here, "message" is the message that it is echoing, <ip-address>
is the ip address of the other end, and <my-pid> is the child's process
id.
- If thechoer gets a UDP packet from someone, it aches the message
and prints
echoing "message"
to: IP = <ip-address>
type = udp
PID = <my-pid>
got echoed message "message"
from: IP = <ip-address>
type = udp (or tcp)
PID = <peer-pid>
the meaning of each field should be clear.
- Your program MUST use select for I/O multiplexing of tcp sockets,
udp socket, and stdin.
- Lastly, the program should fix the problem of the UDP_Echo example. Read
the README file in that example for more details.