gpt4 book ai didi

java - Java的DatagramChannel.write()的含义

转载 作者:行者123 更新时间:2023-11-30 08:12:23 25 4
gpt4 key购买 nike

我最近找到了使用 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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com