Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In this section, you’ll see several Internet servers and clients
that use DatagramPacket and DatagramSocket. Some of these will be familiar
from previous chapters because many Internet protocols have both TCP and
UDP implementations. When an IP packet is received by a host, the host
determines whether the packet is a TCP packet or a UDP datagram by
inspecting the IP header. As I said earlier, there’s no connection
between UDP and TCP ports; TCP and UDP servers can share the same port
number without problems. By convention, if a service has both TCP and
UDP implementations, it uses the same port for both, although there’s no
technical reason this has to be the case.