CS 232 Programming Project: Client-Server Computing

Overview: Most Internet applications consist of two components:

For example, if you run ssh (or scp or sftp) to connect to a remote host, you are actually invoking a client for that service, which contacts an ssh-server on the remote host. As you type commands at the client, they are relayed to the server, which executes them and relays their results back to the client, which displays those results.

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 9876
To 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:


  1. Begin by writing a client that works correctly with my server.
  2. When your client is working correctly, write a simple echo server that echoes back to the client whatever it sends.
  3. Make your echo server multithreaded, so that it can handle multiple connections simultaneously.
  4. Modify your multithreaded echo server so that when the first string it receives is n, it rotates the chars in all subsequent strings it receives before sending them back to the client. From there, it should be easy to complete all remaining requirements.


For the client side, I used these Java classes:

For the server side, I used these Java classes:

Turn in:

Submit your code for your client and your server to /home/cs/232/current/<yourid>/proj6/.

Finally, submit this grading.txt file to /home/cs/232/current/<yourid>/proj6.

Due date: Monday, May 15, 11:59 p.m.

Note: This assignment will not be accepted following the due date.

CS > 232 > Projects > 5

This page maintained by Victor Norman.