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

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!