Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

Are highlighting and punctuation consistent and simple? (375)

Answered: 1 week ago

Question

LO13.1 List the characteristics of monopolistic competition.

Answered: 1 week ago