AIM: DAY TIME SERVER (TCP)
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.
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
- Create the server socket and begin listening.
- Call the accept() method to get new connections.
- Create input and output streams for the returned socket.
- Conduct the conversation based on the agreed protocol.
- Close the client streams and socket.
- Go back to step 2 or continue to step 7.
- Close the server socket.
- Create the client socket connection.
- Acquire read and write streams to the socket.
- Use the streams according to the server's protocol.
- Close the streams.
- Close the socket.
Wating for client request
D:\J2SDK\BIN>java daytime_client a
IT ISMon Apr 05 00:13:42 EST 2004atSMIT-INFOCOME/127.0.0.1