You are on page 1of 2

17EPCS005

PROGRAM:
CLIENT:
import java.net.*;
import java.io.*;
public class dateclient
{
public static void main(String args[])
{
try
{
InetAddress ia=InetAddress.getLocalHost();
System.out.println("InetAddress of this Client is:"+ia);
Socket s=new Socket(ia,65534);
BufferedReader dis=new BufferedReader(new
InputStreamReader(s.getInputStream()));
String sdate=dis.readLine();
System.out.println("Date from Server:"+sdate);
PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
pw.println(ia);

}
catch(IOException e)
{
System.out.println("Exception caught:"+e);
}
}
}
SERVER:
import java.net.*;
import java.io.*;
import java.util.*;
public class dateserver
{
public static void main(String args[])
{
try
{
ServerSocket ss=new ServerSocket(65534);
Socket s=null;
System.out.println("Press ctrl+c to quit !!!");
while(true)
{
s=ss.accept();
PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
Date d=new Date();
String dd=d.toString();
System.out.println("Date in Server:"+dd);
pw.println(dd);
BufferedReader dis=new BufferedReader(new
InputStreamReader(s.getInputStream()));
17EPCS005

String add=dis.readLine();
System.out.println("InetAddress of Client:"+add);
}

}
catch(IOException e)
{
System.out.println("Exception caught:"+e);
}
}
}

OUTPUT