Overview: Most Internet applications consist of two components:
This project is to write the client and server programs for an Caesar Cipher service.
Details. When your client connects to your server, the first thing the client sends is an integer n in the range 1..25. The server replies with this same number to confirm its reception. For any other lines of text the client sends, the server rotates the characters in those lines of text n positions and then returns the rotated text. If the client initially sends something other than an integer in the range 1..25, the server should respond with an error message and close the connection.
Note that non-alphabetic characters should not be rotated -- our version of the Caesar Cipher only affects alphabetic characters (a-z and A-Z).
Note also that if we view this service as a function, one session can serve as the inverse of another session if the first session uses n for its rotation amount and the second session uses 26-n for its rotation amount. Your service should thus be able to both encode and decode messages using the Caesar Cipher.
You are to write a client program that (after displaying an appropriate 'welcome' message), asks for and reads the rotation amount from the user. Using a socket and the TCP protocol, your client should connect to an CaesarCipher server and send it whatever rotation amount the user specified. Your client should receive and display the server's response. Your client should continue reading the user's input, sending it to the server, receiving the server's response, and displaying that response, until the user types quit, at which point your client should close its socket and terminate.
Your client should get the server's hostname and port via command-line arguments. To test your client, you may use my CaesarCipher server that is running on brooks.cs.calvin.edu at port 9876; e.g.:
$ java CaesarCipherClient brooks.cs.calvin.edu 9876
You are also to write your own CaesarCipher 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 receive a message from the client. If the first message is an integer n in the range 1..25, your thread should save n and send it back to the client; otherwise, it should reply with an error message and close its socket.
If it has processed a correct first message, your thread should continue to receive messages from its client and reply with those messages rotated.
Your server should get the port it is to use as a command-line argument; e.g.:
$ java CaesarCipherServer 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:
For the client side, I used these Java classes:
writeBytes()to write out to the stream.
readLine()method: to read from socket and standard input (
System.in). Note that it removes any newline at the end of the string, and returns
nullif the socket was closed.
For the server side, I used these Java classes:
Date, DateFormat, SimpleDateFormat
(int) 'a'(e.g.) to convert a character to its corresponding integer, and
(char) anIntto do the reverse.
Submit your code for your client and your server to
Finally, submit this grading.txt file to
Due date: Monday, May 15, 11:59 p.m.
Note: This assignment will not be accepted following the due date.
CS > 232 > Projects > 5