Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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) { } } }65432eadbce:6a:5x1:5d:4x(1)e::6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started