Question: write a UDP based file transfer program between 2 given IP addresses.PLEASE JAVA CODE SENDER CODE import java.net.*; class Sender { static public void main(String[]

write a UDP based file transfer program between 2 given IP addresses.PLEASE JAVA CODE SENDER CODE import java.net.*; class Sender { static public void main(String[] args) { DatagramSocket Sock; byte[] buf = new byte[ ]{'H','e','l','l','o',' ','w','o','r','l','d'}; try { Sock= new DatagramSocket(6666); InetAddress inetAddress=InetAddress.getByName("127.0.0.1"); DatagramPacket packet= new DatagramPacket(buf,buf.length,inetAddress, 6667); Sock.send(packet); System.out.println("Sent:"+ new String(buf)); Sock.close(); } catch(Exception e) { } } }

RECEIVER CODE

import java.net.*; class Receiver { static public void main(String[] args) { DatagramSocket Sock; byte[] buf = new byte[256]; try { Sock= new DatagramSocket(6667); DatagramPacket packet = new DatagramPacket(buf, buf.length); Sock.receive(packet); System.out.println("Received:" + new String(packet.getData()).trim()+ " From port:"+ packet.getPort()+ " LocalPort:"+Sock.getLocalPort()); Sock.close(); } catch(Exception e) { } } }

write a UDP based file transfer program between 2 given IP addresses.PLEASE

65432eadbce:6a:5x1:5d:4x(1)e::6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!