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

Server Code

Uploaded by

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

Server Code

Uploaded by

fusionkunal0523
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Exp 17_2

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:

You might also like