Google Search

Sunday, October 30, 2011

DAY TIME SERVER (TCP)


AIM: DAY TIME SERVER (TCP)


THEORY:
 
     The time of day is a simple example of a service. Typically, each service is associated with a unique port number on a given server machine. It’s up to the client to know ahead of time which port number the desired service is running on. The system services reserve the use of ports 1 through 1024, so you shouldn’t use those or any other port that you know to be in use. 
 
Instruction:
The two constructors used to create client sockets:
Socket(String hostName,int  port):
It creates a socket connecting the local host to the named host and port. It can also  throws an UnknownHostException or an IOException
Socket(InetAddress ipAdress,int port)
It creates a socket using a preexisting InetAddress object and a port.It can throw an
IOException.

ALGO:
 SERVER SIDE
  1. Create the server socket and begin listening.
  2. Call the accept() method to get new connections.
  3. Create input and output streams for the returned socket.
  4. Conduct the conversation based on the agreed protocol.
  5. Close the client streams and socket.
  6. Go back to step 2 or continue to step 7.
  7. Close the server socket.
CLIENT  SIDE
  1. Create the client socket connection.
  2. Acquire read and write streams to the socket.
  3. Use the streams according to the server's protocol.
  4. Close the streams.
  5. Close the socket.

OUTPUT:
SERVER SIDE:
D:\J2SDK\BIN>java daytime_server
 Wating for client request
closed1connection
CLIENT  SIDE:
D:\J2SDK\BIN>java daytime_client a
 IT ISMon Apr 05 00:13:42 EST 2004atSMIT-INFOCOME/127.0.0.1


0 comments:

Post a Comment