http://www.softlab.ntua.gr/facilities/documentation/unix/unix-socket-faq/unix-socket-faq-4.html

https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/b8a3395f-938b-4347-b6c3-431851e68884/sockets-multicastbroadcast-udp-tcp-soreuseaddr-soreuseport-and-soexclusiveaddruse

The main differences between BSD and Windows are conveniently described on https://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t. According to that, one would say that a solution:

1) For BSD "0" and for Windows "SO_EXCLUSIVEADDRUSE"

2) For BSD "SO_REUSEPORT | SO_REUSEADDR" and for Windows "SO_REUSEADDR"

https://docs.microsoft.com/zh-cn/windows/desktop/WinSock/using-so-reuseaddr-and-so-exclusiveaddruse

Using SO_REUSEADDR

The SO_REUSEADDR socket option allows a socket to forcibly bind to a port in use by another socket. The second socket calls setsockopt with the optname parameter set to SO_REUSEADDR and the optval parameter set to a boolean value of TRUE before calling bindon the same port as the original socket. Once the second socket has successfully bound, the behavior for all sockets bound to that port is indeterminate. For example, if all of the sockets on the same port provide TCP service, any incoming TCP connection requests over the port cannot be guaranteed to be handled by the correct socket — the behavior is non-deterministic. A malicious program can use SO_REUSEADDR to forcibly bind sockets already in use for standard network protocol services in order to deny access to those service. No special privileges are required to use this option.

If a client application binds to a port before a server application is able to bind to the same port, then problems may result. If the server application forcibly binds using the SO_REUSEADDR socket option to the same port, then the behavior for all sockets bound to that port is indeterminate.

The exception to this non-deterministic behavior is multicast sockets. If two sockets are bound to the same interface and port and are members of the same multicast group, data will be delivered to both sockets, rather than an arbitrarily chosen one.

windows没有SO_REUSEPORT选项,只有SO_REUSEADDR,但

windows的SO_REUSEADDR 等同于BSD的SO_REUSEADDR和SO_REUSEPORT

但如果两个socket同时绑定到同一地址和同一port的话,这些socket的行为是不确定的,主要体现在接收数据上,数据会投递给随机选择的一个socket。

所以,两个socket绑定到同一地址和同一port,同时用udp接收数据的话,只有一个socket能够收到数据。

这样是不行的。只能用一个socket。

能否不同udp socket绑定到同一IP地址和port的更多相关文章

  1. mysql绑定多个ip地址

    http://jpuyy.com/2013/07/mysql-bind-multi-address.html mysql绑定多个ip地址 发表于2013 年 7 月 1 日 my.cnf中有选项bin ...

  2. Tomcat绑定多个IP地址 多域名绑定

    http://blog.csdn.net/stevenyanzhi/article/details/6029776 Tomcat绑定多个IP地址 如果一台服务机上有多个IP地址又有多个工程如何一个IP ...

  3. 一台服务器绑定多个ip地址

    一台服务器绑定多个ip地址. 方法一: 使用标准的网络配置工具(比如ifconfig和route命令)添加lP别名: 在eth0网卡再绑定一个ip:192.168.101.103 /sbin/ifco ...

  4. Redis绑定多个ip地址

    Redis绑定多个ip地址 学习了:https://www.zhihu.com/question/20346112/answer/17157379 注意,用空格进行分隔 bind 127.0.0.1 ...

  5. linux系统单网卡绑定多个IP地址

    说明: 单网卡绑定两个IP地址,电信和联通,目的:是为了当电信出故障联通正常使用. 系 统 IP地址 子网掩码 网关 CentOS 6.3_64bit eth0:116.18.176.19 255.2 ...

  6. Android中验证输入是否为汉字及手机号,邮箱验证,IP地址可用port号验证

    1,验证是否为汉字 // 验证昵称 private boolean verifyNickname() { String nickname = edt_username.getText().toStri ...

  7. Linux socket编程 DNS查询IP地址

    本来是一次计算机网络的实验,但是还没有完全写好,DNS的响应请求报文的冗余信息太多了,不只有IP地址.所以这次的实验主要就是解析DNS报文.同时也需要正确的填充请求报文.如果代码有什么bug,欢迎指正 ...

  8. Linux下的C Socket编程 -- 获取对方IP地址

    Linux下的C Socket编程(二) 获取域名对应的IP地址 经过上面的讨论,如果我们想要连接到远程的服务器,我们需要知道对方的IP地址,系统函数gethostbyname便能够实现这个目的.它能 ...

  9. 华为S5700设置vlan,并绑定电脑的IP地址与mac地址。

    要求是设置两个vlan,10和20.交换机下的10网段和20网段的电脑在两个vlan当中.20网段的ip地址与mac地址绑定,从而实现下面的电脑更改ip地址或者不明来源的电脑不能连接到交换机. 1.s ...

随机推荐

  1. 【Spring Boot 源码解读】之 【为何引入了 Jedis 依赖最后用的还是 Lettuce 客户端?】

    1.Spring Boot 2.x 的两种 Redis 客户端 首先,我们都知道,从 Spring Boot 2.x 开始 Lettuce 已取代 Jedis 成为首选 Redis 的客户端.当然 S ...

  2. python关系(比较)运算符

    关系运算符 就是 比较运算符 a.对象的值进行比较 数字间的比较运算符连着使用: 数字与True.False的比较True 表示 1 , False 表示 0 数字与字符串的比较(不能比较) 字符串间 ...

  3. 安装SQL的时候,设置用户权限失败

    在安装sql的时候,遇到一个问题: 在查看报表明细中,提示: 就是这三个: 首先确保你是使用管理员用户安装的,如果还不行,运行 secpol.msc 进入本地安全策略 把自己的用户名加入进来就好了.

  4. OpenGLES思维导图

    两本书到头来就只剩下了这三张图了吧.想要原图:https://github.com/wangwangla/biji/blob/master/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8 ...

  5. git 删除和复制远程分支 储藏

    不常用到命令经常查,特别记录,方便自己开箱即用. 1. 删除本地分支 git branch -D <dev> 2. 删除远程分支 git push origin --delete < ...

  6. 关于neo4j初入门(3)

    这一章主要是函数的部分 UPPER 它需要一个字符串作为输入并转换为大写字母. UPPER (<input-string>)<input-string>可以是来自Neo4J数据 ...

  7. 创建Account控制器 安全性与收尾工作 精通ASP-NET-MVC-5-弗瑞曼

  8. Apache Commons 相关工具类使用

    Apache Commons Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.下面是我这几年做开发过程中自己用过的工具类做简单介绍. 组件 功能介绍 ...

  9. CF572_Div2_D2

    题意 http://codeforces.com/contest/1189/problem/D2 思考 显然地,如果出现度数为2且两条出边边权不相同的情况,是无法构造合法方案的. 下面考虑缩边后的树, ...

  10. linux之samba使用

    工作中,很多时候,我导出文件,或者上传文件的时候经常失败,报samba fail,但我并不知道samba是干什么用的,也老是听同事说什么samba没有挂载,但我基本上不知道什么是samba,更不要说什 ...