Server Code
Server Code
Server Code:
import java.io.*;
import java.net.*;
public class Exp17_Ex3_server {
public static void main(String args[]) throws IOException {
byte b[] = new byte[3072];
DatagramSocket dsoc = new DatagramSocket(1000);
FileOutputStream f = new FileOutputStream("Z:\\Sem 5\\ajp\\man programs\\17_3\\sfile.txt");
while (true) {
DatagramPacket dp = new DatagramPacket(b, b.length);
dsoc.receive(dp);
System.out.println(new String(dp.getData(), 0, dp.getLength()));
}
}
}
Client Code:
import java.io.*;
import java.net.*;
public class Exp17_Ex3_client
{
public static void main(String args[])throws Exception{
byte b[]=new byte[1024];
FileInputStream f=new FileInputStream("cfile.txt");
DatagramSocket dsoc=new DatagramSocket(2000);
int i=0;
while(f.available()!=0)
{
b[i]=(byte)f.read();
i++;
}
f.close();
dsoc.send(new
DatagramPacket(b,i,InetAddress.getLocalHost(),1000));}
}
Before:
After: