能否不同udp socket绑定到同一IP地址和port
http://www.softlab.ntua.gr/facilities/documentation/unix/unix-socket-faq/unix-socket-faq-4.html
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的更多相关文章
- mysql绑定多个ip地址
http://jpuyy.com/2013/07/mysql-bind-multi-address.html mysql绑定多个ip地址 发表于2013 年 7 月 1 日 my.cnf中有选项bin ...
- Tomcat绑定多个IP地址 多域名绑定
http://blog.csdn.net/stevenyanzhi/article/details/6029776 Tomcat绑定多个IP地址 如果一台服务机上有多个IP地址又有多个工程如何一个IP ...
- 一台服务器绑定多个ip地址
一台服务器绑定多个ip地址. 方法一: 使用标准的网络配置工具(比如ifconfig和route命令)添加lP别名: 在eth0网卡再绑定一个ip:192.168.101.103 /sbin/ifco ...
- Redis绑定多个ip地址
Redis绑定多个ip地址 学习了:https://www.zhihu.com/question/20346112/answer/17157379 注意,用空格进行分隔 bind 127.0.0.1 ...
- linux系统单网卡绑定多个IP地址
说明: 单网卡绑定两个IP地址,电信和联通,目的:是为了当电信出故障联通正常使用. 系 统 IP地址 子网掩码 网关 CentOS 6.3_64bit eth0:116.18.176.19 255.2 ...
- Android中验证输入是否为汉字及手机号,邮箱验证,IP地址可用port号验证
1,验证是否为汉字 // 验证昵称 private boolean verifyNickname() { String nickname = edt_username.getText().toStri ...
- Linux socket编程 DNS查询IP地址
本来是一次计算机网络的实验,但是还没有完全写好,DNS的响应请求报文的冗余信息太多了,不只有IP地址.所以这次的实验主要就是解析DNS报文.同时也需要正确的填充请求报文.如果代码有什么bug,欢迎指正 ...
- Linux下的C Socket编程 -- 获取对方IP地址
Linux下的C Socket编程(二) 获取域名对应的IP地址 经过上面的讨论,如果我们想要连接到远程的服务器,我们需要知道对方的IP地址,系统函数gethostbyname便能够实现这个目的.它能 ...
- 华为S5700设置vlan,并绑定电脑的IP地址与mac地址。
要求是设置两个vlan,10和20.交换机下的10网段和20网段的电脑在两个vlan当中.20网段的ip地址与mac地址绑定,从而实现下面的电脑更改ip地址或者不明来源的电脑不能连接到交换机. 1.s ...
随机推荐
- 快速回顾MySQL:汇总和分组
10.3 汇总数据 我们经常需要汇总数据而不用把它们实际检索处出来,为此MySQL提供了专门的函数.使用这些函数,MySQL查询可用于检索数据,以便分析和报表的生成.这种类型的检索例子有以下几种: 确 ...
- 图解kubernetes scheduler基于map/reduce无锁设计的优选计算
优选阶段通过分离计算对象来实现多个node和多种算法的并行计算,并且通过基于二级索引来设计最终的存储结果,从而达到整个计算过程中的无锁设计,同时为了保证分配的随机性,针对同等优先级的采用了随机的方式来 ...
- 带限制的广搜 codeforces
You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each ...
- java实现FTP文件下载
package com.vingsoft.util;/*** @author 作者:dujj* @version 创建时间:2020年1月13日 下午5:53:39*/import java.io.F ...
- .net core mysql CodeFirst
创建两个项目 1.网站 2.Model层 引用DLL Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.Design Micros ...
- 解决python爬虫requests.exceptions.SSLError: HTTPSConnectionPool(host='XXX', port=443)问题
爬虫时报错如下: requests.exceptions.SSLError: HTTPSConnectionPool(host='某某某网站', port=443): Max retries exce ...
- 学习 解决用户验证、单点登录、api访问控制的开源框架 的 十月 第一弹:
step one 去饭 源码 ps :https://identityserver.io/ 这个官网. ps: https://github.com/IdentityServer 这是 源码网
- 大叔 Frameworks.Entity.Core 2 PageList
Frameworks.Entity.Core\Commons\PageList\ 1 分页通用类 ListPageList<T> 继承 PageListBase<T>, IP ...
- SpringBoot整合三大组建(Servlet、Listener、Filter)
>[更多资源和教程请关注公众号:**非科班的科班**.如果觉得我写的还可以请给个赞,谢谢大家,你的鼓励是我创作的动力](https://blog.csdn.net/qq_43255017)## ...
- mysq5.7l的下载与配置
---恢复内容开始--- mysql是一个开源免费的数据库,它属于oracle公司 下载地址:www.oracle.com 页面移动到下面可以找到这几个选项 还是移动到下面 如果你要下载的不是那四样中 ...