Exp8 MCN
Exp8 MCN
Exp8 MCN
EXPERIMENT 8
TITLE: Client Server Program to display Server Machine Date and Time on the Client
Machine
AIM: To implement Client Server Program to display Server Machine Date and Time on
the Client Machine using Java
THEORY: In this program, we make use of sockets. We use java.net, java.io and
java.util packages. The java.net package provides with classes for implementing the
networking related application. Java.io is concerned with the system input and output
operations as well as classes such as DataOutputStream, DataInputStream,
BufferedReader, etc. Java.util provides creation of applets as well classes that facilitate
communication between different applets.
Two programs are required, the Server program and the Client program. The Serve
Program contains a class called DateServer in which a ServerSocket object from
java.net is created and connected a given port number, here port number is 5217.
Then, a while loop runs which waits for a connection with the port. An object soc of
class Socket is initialised to get the connection of the socket to the port number given.
An object of the DataOutputStream is initialised to get the output stream from the
socket object. The writeBytes method will pass this output stream data as a string to
the client side program. The objects are then closed.
In the Client side program, DateClient, an object soc of Socket class is initialised and
passed the same localhost address (port number) which the server program connected
to. It uses a BufferedReader to convert the string output obtained from the server
program into easily readable text. The system then prints this output.
CODE
DateClient.java
DateServer.java
OUTPUT