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. cogs 3008. 朋友圈

    3008. 朋友圈 ★★   输入文件:friendscircle.in   输出文件:friendscircle.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] NO ...

  2. 基于AOP和ThreadLocal实现的一个简单Http API日志记录模块

    Log4a 基于AOP和ThreadLocal实现的一个简单Http API日志记录模块 github地址 : https://github.com/EalenXie/log4a 在API每次被请求时 ...

  3. MySQL 行列相互转换

    行列相互转换 /*创建表*/ CREATE TABLE ic ( NAME ), Product ), amount INT ); INSERT INTO ic VALUES (), (), (), ...

  4. 洛谷 P1463 [POI2002][HAOI2007]反素数

    题目链接 题目描述 对于任何正整数x,其约数的个数记作g(x).例如g(1)=1.g(6)=4. 如果某个正整数x满足:g(x)>g(i) 0<i<x,则称x为反质数.例如,整数1, ...

  5. python 快速创建字典 fromkes()

    作用:快速创建字典 特点:共用value seq = ['google', 'ie', 'firefox'] # seq为可迭代对象(str, list, tuple, dict, set) dic ...

  6. 关于SOA架构设计的案例分析

    关于SOA架构设计的案例分析 面向服务的体系结构(SOA)是一个组件模型,它将应用程序的不同功能单元(称为服务)通过这些服务之间定义良好的接口和契约联系起来.它可以根据需求通过网络对松散耦合的粗粒度应 ...

  7. NOI2.5 1253:Dungeon Master

    描述 You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of ...

  8. 笔记常用Linux命令(二) 进程和端口

    查看系统进程 ps:用于报告当前系统的进程状态 a:显示所有终端机下执行的程序 ps -ef/ps aux: 这两个命令都是查看当前系统正在运行进程,两者的区别是展示格式不同. 如果想要查看特定的进程 ...

  9. [Ubuntu]解决"系统的网络服务与此版本的网络管理器不兼容"提示

    先贴方法: sudo -s ' 获取root权限 apt-get install network-manager ' 重装网络管理器 如果系统提示有升级包可用则安装即可. 开机后,右上角没有网络图标. ...

  10. JS中for...in循环陷阱及遍历数组的方式对比

    JavaScript中有很多遍历数组的方式,比较常见的是for(var i=0;i<arr.length;i++){},以及for...in...循环等,这些遍历都有各自的优缺点,下面来看看各种 ...