简体   繁体   English

为什么java.net.DatagramSocket支持“连接”状态?

[英]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? 关于这个问题 :java.net.DatagramSocket支持“连接”状态的背景是什么?

I would have expected that the isConnected() method always returns false, since UDP/datagram sockets do not support a connected state . 我本来希望isConnected()方法始终返回false,因为UDP /数据报套接字不支持连接状态 But a quick look at the sources shows that there is some logic behind the isConnected() method. 但是快速查看源代码可以发现isConnected()方法背后有一些逻辑。 Why? 为什么?

Read the Javadoc. 阅读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. 当您将DatagramSocket “连接”到远程IP /端口时,您只是在告诉套接字不要接受去往或来自任何其他远程主机的数据包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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