Overview: Most Internet applications consist of two components:
One of the standard TCP/IP services is the echo service, in which a server waits for a client to connect, reads whatever line of text the client sends it as a string, and replies to the client with the same string.
This project is to write the client and server programs for an echo service, with the following extension: If the first line the client sends consists of the word rot13, then for all subsequent lines the server receives from the client, the server rotates the alphabetic characters 13 positions and then replies to the client with those rotated strings.
Details.
The rot13 encoding technique is a simple way to scramble text messages to make them unreadable to the casual reader. (Usenet news groups often display spoilers or offensive material using rot13.)
The mechanism is to "rotate" each alphabetic character 13 positions (maintaining its case), so that alphabetic characters are mapped to one another as follows:
| original char |
a | b | c | ... | m | n | o | ... | z | A | B | C | ... | M | N | O | ... | Z |
| rot13 char |
n | o | p | ... | z | a | b | ... | m | N | O | P | ... | Z | A | B | ... | M |
Note that non-alphabetic characters are not rotated -- rot13 only affects alphabetic characters. Thus, the rot13 of adams is nqnzf, the rot13 of Adams is Nqnzf, the rot13 of Nqnzf is Adams, and the rot13 of 123adams456 is 123nqnzf456.
Note also that if we view rot13 as a function, then it is its own inverse function:
rot13( rot13( aChar ) ) == aCharThat is, we can use rot13 to unscramble a character that was scrambled using rot13.
You are to write a client program that, using a socket and the TCP protocol, connects to a Rot13Echo server and sends it whatever line of input the user types. Your client should then receive and output the server's response. Your client should continue sending and receiving the user's input, until the user types quit, at which point your client should close its socket and terminate.
Your client should get the server's host-name and port via command-line arguments. To test your client, you may use my Rot13Echo server that is running on acolyte at port 9876; e.g.:
$ java Rot13EchoClient acolyte 9876
You are also to write your own Rot13Echo server. Your server should open a TCP socket, and listen for a client's connection. When contacted by a client, your server should spawn off a new thread to handle the session with that particular client, and then listen for the next client connection.
Your thread should read the first message from the client. If that first message is rot13, your thread should set a boolean flag to "rotate" all subsequent messages from the client, and then reply to the client with rot13; otherwise, it should just send what it received back to the client.
Once it has processed the first message, your thread should continue to receive messages from its client and either echo them or send those messages rotated, based on the value of your flag.
Your server should get the port it is to use as a command-line argument. For example, if you write your server in Java, you might run it as follows:
$ java Rot13EchoServer 9876To help trace its execution, your server should display the date, time and the IP address of the client each time it receives a new connection.
You may write your system in any of the following languages:
http://www.uwo.ca/its/doc/courses/notes/socket/
http://www.fnal.gov/docs/products/perl/pod.new/5.00503/pod/perlthrtut.html
Strategy.
Turn in:
A. On acolyte use script to create a file in which you
Print your script files and attach a hard copy of this grade sheet.
Due date: Tue, May 8 -- 11:59 p.m.
Note: This assignment will not be accepted following the due date.