0% found this document useful (0 votes)
29 views2 pages

Answer Key

The document contains code for a client and server program that communicate over a socket connection. The client program connects to the server, receives the current date from the server, and sends its own IP address. The server program listens for connections on a port, sends the current date to clients when they connect, and receives the client's IP address.

Uploaded by

jo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Answer Key

The document contains code for a client and server program that communicate over a socket connection. The client program connects to the server, receives the current date from the server, and sends its own IP address. The server program listens for connections on a port, sends the current date to clients when they connect, and receives the client's IP address.

Uploaded by

jo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like