Summary
In this chapter, we examined the nature of the UDP protocol and how Java supports it. We contrasted TCP and UDP to provide some guidance in deciding which protocol was best for a given problem.
We started with a simple UDP client/server to demonstrate how the DatagramPacket and DatagramSocket classes are used. We saw how the InetAddress class was used to obtain addresses used by sockets and packets.
The DatagramChannel class supports using NIO techniques in a UDP environment, which can be more efficient than using the DatagramPacket and DatagramSocket approach. The approach used a byte buffer to hold messages that were sent between a server and a client. This example illustrated many of the techniques that were developed in Chapter 3,
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access