O'Reilly logo

Java™ Network Programming and Distributed Computing by Michael Reilly, David Reilly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.3. DatagramSocket Class

The DatagramSocket class provides access to a UDP socket, which allows UDP packets to be sent and received. A DatagramPacket is used to represent a UDP packet, and must be created prior to receiving any packets. The same DatagramSocket can be used to receive packets as well as to send them. However, read operations are blocking, meaning that the application will continue to wait until a packet arrives. Since UDP packets do not guarantee delivery, this can cause an application to stall if the sender does not resubmit packets. You can use multiple threads of execution, discussed in Chapter 7, or as of JDK1.1, you can use nonblocking I/O to avoid this problem, as shown in the EchoClient example discussed in Section 5.7.2 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required