CS 742 - Computer Communication Networks - Program 1 - Name:_____________ DUE: Friday, October 25, 2002 (100 points) o Put your name and add some necessary comments into these code when necessary. These are a part of grading in this assignment. o Write one page document describing the programs you create and the user's guide. o Use the handin system to submit all code electronically. The submission ID is 1. 1. Write a client and server program according to the following specifications using C/C++: (50 points) (1) Client connects to server and sends COMMAND(s) to server. (2) Server will listen on some port (must use last 4 digit of SSN # as your port number). (3) Client will send hostname along with port number to connect in the COMMAND sequence. The COMMAND should look like this: CONNECT hostname port-number e.g: CONNECT host:kirk.cs.twsu.edu port:80 (note: CONNECT is in capital) (4) Server will read the COMMAND sequence from client, parse it and try to establish connection to (host,port) specified by client. If client issues wrong COMMAND then server will write back 'Invalid COMMAND' to client, else it will read data from remote host and write it back to client console. If server will be unable to connect to remote host specified by client it will write 'HOST:hostname(port) is not at your service'. (5). You must verify that you program is working good for at least these ports (80,25,13). 2. Write the same program using Java. (50 points) SAMPLE SESSION: --------------- > ./server Server ready to accept connections wireless.cs.twsu.edu(1222) ==> issued 'COMMAND host:www.google.com port:80' kirk.cs.twsu.edu(3332) ==> issued 'COMMAND host:kirk.cs.twsu.edu port:25' sisko.cs.twsu.edu(1211) ==> issued 'COMMAND host:www.cisco.com port:13' web.eecs.mit.edu ==> issued 'COMMAND host:blah-blah port:11' 156.21.1.1 ==> issued 'COMMAND host:www.yahoo.id port:1111' (BONUS) www.wichita.edu ==> issued 'COMMAND host:wireless port:111 host:yahoo.com port:1111 host:google.com port:1111 > ./client COMMAND host:kirk.cs.twsu.edu port:13 Wed Sep 25 00:20:06 2002 Connection closed by server COMMAND host:kirk.cs.twsu.edu port:25 220 kirk.cs.twsu.edu ESMTP Exim 3.35 #1 Wed, 25 Sep 2002 00:21:12 -0500 quit 221 kirk.cs.twsu.edu closing connection Connection closed by server CONNECT host:blah-blah port:11 HOST:blah-blah(11) is not at your service BONUS part: COMMAND host:kirk.cs.twsu.edu port:25 host:sisko.cs.twsu.edu:13 220 kirk.cs.twsu.edu ESMTP Exim 3.35 #1 Wed, 25 Sep 2002 00:21:12 -0500 quit 221 kirk.cs.twsu.edu closing connection Connection closed by server Wed Sep 25 00:20:06 2002 Connection closed by server EXPLANATION OF SESSION : ----------------------- We started server by './server', server prints message 'Server ready to accept connections', now whenever some client connects, it prints client FQDN(if possible else will print client IP) along with client's remote port number in (port-number). Then it prints COMMAND text issued by client. If you notice, the fourth command(mit one) actually will make server to send back 'HOST: hostname is not at your service' to client. We started client by './client', client is ready to accept read from input and send it to server. we issued several commands , in the first command 'COMMAND host: kirk.cs.twsu.edu port:13' , we read date from server , in second we read SMTP server response. Look at diagram: __________ ----------- __________ | | COMMAND | | CONNECT | | | CLIENT | <----------> | SERVER | <-------> | REMOTE | | | | | | HOST | |__________| |___________| |__________| COMMAND ==> CONNECT host:kirk.cs.twsu.edu port:25 so remote host is kirk.cs.twsu.edu, your server will attempt to connect to kirk.cs.twsu.edu on port 25 Please note down, whenever server <----> remote host connection closes server inform back to client , and client will display 'Connection closed by server' on its console SANITY CHECKS ------------- You need to make sure all possible cases that can crash your server and client , such as : i) There should be no spaces between host and : and or port and : i) LIMIT COMMAND Sequence length, else SERVER will not accept that COMMAND say COMMAND text can only be of 100 characters. BONUS POINTS (20 points) ------------ 1- If you will be able to handle COMMAND sequence like this one CONNECT host:kirk.cs.twsu.edu port:25 host:sisko.cs.twsu.edu port:13 Observe, you can specify multiple hosts in one line , in this case your server will open connection one by one to remote host(s) at specified ports in sequence and gives the output back to client in order. CONNECT host:kirk.cs.twsu.edu port:25 host:sisko.cs.twsu.edu:13 server --> Connection #1 : make connection to kirk port 25. When Connection #1 is closed, it immediately opens Connection #2; sisko.cs.twsu.edu at port 13 For each connection, the conditions are same as described above. 2 - If you will be able to handle multiple clients at one time. (either through thread of fork()). OPTIONS: -------- - You can use TCP or UDP whatever you want.