简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM