//TDSERVER

import java.net.*;

import java.io.*;

import java.util.*;

import java.text.*;

class tdserver

{

public static void main(String a[]) throws Exception

{

ServerSocket ss;

Socket s;

PrintStream p;

DataInputStream din;

Date d1=new Date();

ss=new ServerSocket(8000);

s=ss.accept();

while(true)

{

try

{

din=new DataInputStream(s.getInputStream());

p=new PrintStream(s.getOutputStream());

String s1=din.readLine();

if(s1.equals(“date”))

{

DateFormat df=DateFormat.getDateInstance(DateFormat.SHORT);

p.println(df.format(d1));

}

else

{

DateFormat df=DateFormat.getTimeInstance(DateFormat.SHORT);

p.println(df.format(d1));

}

}

catch(IOException e)

{

System.out.println(“Client terminated”);

System.exit(1);

}

}

}

}

//TDCLIENT

import java.io.*;

import java.net.*;

public class tdclient

{

public static void main(String a[])

{

Socket s;

String hostname,msg;

DataInputStream din;

DataInputStream din1;

PrintStream p;

try

{

s=new Socket(“localhost”,8000);

din=new DataInputStream(s.getInputStream());

p=new PrintStream(s.getOutputStream());

din1=new DataInputStream(System.in);

while(true)

{

System.out.print(“\n\nEnter Date to Retrieve date and time to Time : “);

msg=din1.readLine();

if(msg.equals(“quit”)) break;

p.println(msg);

System.out.print(“\n\nThe “+msg+ ” is : “);

System.out.print(din.readLine());

}

}

catch(Exception e)

{

System.out.println(e);

}

}

}

Advertisements