sockets - read() 形成一个未绑定(bind)的套接字?

标签 sockets udp posix bind

如果从一个未绑定(bind)的套接字读取会发生什么?更具体地说是在 UDP 套接字上?

如果套接字已用于发送信息,则套接字将绑定(bind)到端口(和地址),因此我们将监听该端口(地址,端口),但是如果套接字完全未绑定(bind),那么预期的行为是什么?
在这种情况下,该套接字将如何响应 select/epoll 以进行读取操作?

最佳答案

它有各种指定或未指定。

从 man 7 udp (Linux):

In order to receive packets, the socket can be bound to a local address first by using bind(2). Otherwise the socket layer will automatically assign a free local port out of the range defined by /proc/sys/net/ipv4/ip_local_port_range and bind the socket to INADDR_ANY.



来自 MSDN recv() function :

The local address of the socket must be known. For server applications, use an explicit bind function or an implicit accept or WSAAccept function. Explicit binding is discouraged for client applications. For client applications, the socket can become bound implicitly to a local address using connect, WSAConnect, sendto, WSASendTo, or WSAJoinLeaf.





WSAEINVAL: The socket has not been bound with bind, ...



我无法回答 BSD、Solaris、HP-UX、AIX、...

关于sockets - read() 形成一个未绑定(bind)的套接字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44741609/

相关文章:

node.js - Azure 上使用 NodeJS 的 Websocket

Java TCP 套接字嗅探

java - UDP 服务器从客户端获取数据,即使服务器是最后启动的

python - Ruby 与 Python - 套接字库

linux - 输出到脚本目录中的文件

c++ - 强制 boost 使用 POSIX 共享内存而不是 System V?

sockets - Azure Web App 套接字数量有什么限制?

java - 使用 read 与 IOUtils.copy 从 InputStream 读取

android - Android 中的 RTSP 客户端

c++ - 如何在 Linux 中实用地检索连接的接入点信息