Search code examples
javasocketsdatagram

Why does java.net.DatagramSocket support a "connected" state?


In reference to this question: What is the background that a java.net.DatagramSocket supports a "connected" state?

I would have expected that the isConnected() method always returns false, since UDP/datagram sockets do not support a connected state. But a quick look at the sources shows that there is some logic behind the isConnected() method. Why?


Solution

  • Read the Javadoc. When you "connect" a DatagramSocket to a remote IP/port you are just telling the socket not to accept packets to or from any other remote host.