Java socket programming (Due: March 20, 06 12:00 midnight).

Overview

In this lab you will modify and build three different servers.  Servers are nothing but programs that wait for requests from clients and serve their requests.  You will have to use Java.

Details

1. Download the TCP server and please go through the code.  It is commented.  Compile the code using any Java compiler.  You can use Text Editor: Ctrl+1 compiles the code and Ctrl+2 runs the code.  Once you compile successfully.  Run the code.

Testing the TCP server. Using a terminal on your linux boxes.  Type the following commands to connect to the TCP server that you are running.

telnet ip_address_of_the_computer_your_code_is_running port_number

Then type in a sentence and hit enter and see what you get back.  You will notice that each time client sends and gets back a sentence the client needs to make a fresh connection.  Modify the code of TCP server so that you don't have to do that. (Hint: Once the client connects loop through getting sentences from client and sending them back until client sends an empty line.  You need to add a loop and you can use clientSentence.length==0 condition to break the loop.)

This modified version of TCP server has to be used for the work below.

2. Echo server

Modify TCP server so that the client sees back exactly what it sends to the server. (Hint: Donot capitalize.)

3. DayTime server

Modify TCP server so that the client gets back date and time when the connection was made. You will not need inFromClient variable.  You can use Date class to get the current date and time.  Date class is available in java.util package.

Usage hints:

import java.util.*;

Date objDate = new Date();

String strToday = objDate.toString();

4. Discard server

Modify TCP server so that the client does not get back anything.  (Hint: Donot send back any data to client.).

5. Testing all the servers is similar to testing TCP server.

6. Submit (to nagesh@temple.edu)


Email subject: 230-xxxx-Lab-y

(xxxx- last four digits of your TUID, y-lab number)

Email content: Code of all the four servers viz. modified TCP server, Echo server, DayTime server, Discard server.