Question
udp client and server write the program import java.net.*; import java.io.*; public class udpclient{ public static void main(string args[]){ // args give message contents and
udp client and server write the program import java.net.*; import java.io.*; public class udpclient{ public static void main(string args[]){ // args give message contents and server hostname datagramsocket asocket = null; try { asocket = new datagramsocket(); byte [] m = args[0].getbytes(); inetaddress ahost = inetaddress.getbyname(args[1]); int serverport = 6789; datagrampacket request = new datagrampacket(m, m.length, ahost, serverport); asocket.send(request); byte[] buffer = new byte[1000]; datagrampacket reply = new datagrampacket(buffer, buffer.length); asocket.receive(reply); system.out.println("reply: " + new string(reply.getdata())); }catch (socketexception e){system.out.println("socket: " + e.getmessage()); } catch (ioexception e){system.out.println("io: " + e.getmessage()); } finally { if(asocket != null) asocket.close(); } } }
2. save the program and compile it
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