我最近发现使用 DatagramChannel.write()
的代码。该代码仅在连接之前询问主机 IP 和端口,然后允许发送(通过 DatagramChannel.write() )。
作为网络编程新手,它不请求目标 IP/端口似乎很奇怪。为什么不呢?
Oracle 的文档指出
This method may only be invoked if this channel's socket is connected, in which case it sends datagrams directly to the socket's peer.
“套接字的对等点”是什么意思?
最佳答案
Being new to network programming, it seemed odd that it wouldn't request the destination IP/port. Why not?
因为之前connect().
中已经指定了
Oracle's documentation states
block 引用>This method may only be invoked if this channel's socket is connected, in which case it sends datagrams directly to the socket's peer. What does it mean by "the socket's peer"?
目标IP:您连接 channel 的端口。
关于java - Java的DatagramChannel.write()的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30535210/