Program to send date using UDP Protocol
Server Code:
import java.io.*;
import java.net.*;
import java.util.*;
class udpehs
{
public static void main(String ar[]) throws Exception
{
String clsent,ssent;
DatagramSocket ssoc=new DatagramSocket(3232);
InetAddress ip=InetAddress.getLocalHost();
clsent=(new Date()).toString();
byte buf[]=clsent.getBytes();
ssoc.send(new DatagramPacket(buf,buf.length,ip,32));
ssoc.close();
}
}
Client code:
import java.io.*;
import java.net.*;
import java.util.*;
class udpehc
{
public static void main(String ar[]) throws Exception
{
DatagramSocket ssoc=new DatagramSocket(32);
byte buf[]=new byte[1024];
DatagramPacket dpack=new DatagramPacket(buf,buf.length);
ssoc.receive(dpack);
String df=new String(dpack.getData());
System.out.println(df);
ssoc.close();
}
}
Output:
Server Code:
import java.io.*;
import java.net.*;
import java.util.*;
class udpehs
{
public static void main(String ar[]) throws Exception
{
String clsent,ssent;
DatagramSocket ssoc=new DatagramSocket(3232);
InetAddress ip=InetAddress.getLocalHost();
clsent=(new Date()).toString();
byte buf[]=clsent.getBytes();
ssoc.send(new DatagramPacket(buf,buf.length,ip,32));
ssoc.close();
}
}
Client code:
import java.io.*;
import java.net.*;
import java.util.*;
class udpehc
{
public static void main(String ar[]) throws Exception
{
DatagramSocket ssoc=new DatagramSocket(32);
byte buf[]=new byte[1024];
DatagramPacket dpack=new DatagramPacket(buf,buf.length);
ssoc.receive(dpack);
String df=new String(dpack.getData());
System.out.println(df);
ssoc.close();
}
}
Output:
0 comments:
Post a Comment