linux下 端口复用的问题

解决性参考:Currently, Linux does not allow reuse of same local port for both TCP server and TCP client.而且小测试程序能够成功,和我的库测试程序的差别也就在这一点了,因此接受连接和发起连接的端口分开即可。

其他资料:

这个是捣乱最大的:http://www.ajaxstu.com/Linuxbiancheng/294968.html 请问:linux难道没有端口重用吗?我用SO_REUSEPORT报找不到

已经搞定,需要改/usr/include/asm/socket.h:/* To add :#define SO_REUSEPORT 15 */

http://hi.baidu.com/qiaoyong/blo ... b1f4190ff47707.html

freebsd与linux下bind系统调用小结

只考虑AF_INET的情况(同一端口指ip地址与端口号都相同)

1.freebsd支持SO_REUSEPORT和SO_REUSEADDR选项,而linux只支持SO_REUSEADDR选项。

2.freebsd下,使用SO_REUSEPORT选项,两个tcp的socket可以绑定同一个端口;同样,使用SO_REUSEPORT选项,两个udp的socket可以绑定同一个端口。

3.linux下,两个tcp的socket不能绑定同一个端口;而如果使用SO_REUSEADDR选项,两个udp的socket可以绑定同一个端口。

4.freebsd下,两个tcp的socket绑定同一端口,只有第一个socket获得数据。

5.freebsd下,两个udp的socket绑定同一端口,如果数据包的目的地址是单播地址,则只有第一个socket获得数据,而如果数据包的目的地址是多播地址,则两个socket同时获得相同的数据。

6.linux下,两个udp的socket绑定同一端口,如果数据包的目的地址是单播地址,则只有最后一个socket获得数据,而如果数据包的目的地址是多播地址,则两个socket同时获得相同的数据。

http://cache.baidu.com/c?m=9d78d ... er=baidu&fast=y

Unix网络API

SO_REUSEADDR和SO_REUSEPORT

SO_REUSEADDR提供如下四个功能:

SO_REUSEADDR允许启动一个监听服务器并捆绑其众所周知端口,即使以前建立的将此端口用做他们的本地端口的连接仍存在。这通常是重启监听服务器时出现,若不设置此选项,则bind时将出错。

SO_REUSEADDR允许在同一端口上启动同一服务器的多个实例,只要每个实例捆绑一个不同的本地IP地址即可。对于TCP,我们根本不可能启动捆绑相同IP地址和相同端口号的多个服务器。

SO_REUSEADDR允许单个进程捆绑同一端口到多个套接口上,只要每个捆绑指定不同的本地IP地址即可。这一般不用于TCP服务器。

SO_REUSEADDR允许完全重复的捆绑:当一个IP地址和端口绑定到某个套接口上时,还允许此IP地址和端口捆绑到另一个套接口上。一般来说,这个特性仅在支持多播的系统上才有,而且只对UDP套接口而言(TCP不支持多播)。

SO_REUSEPORT选项有如下语义:

此选项允许完全重复捆绑,但仅在想捆绑相同IP地址和端口的套接口都指定了此套接口选项才性。

如果被捆绑的IP地址是一个多播地址,则SO_REUSEADDR和SO_REUSEPORT等效。

使用这两个套接口选项的建议:

在所有TCP服务器中,在调用bind之前设置SO_REUSEADDR套接口选项;

当编写一个同一时刻在同一主机上可运行多次的多播应用程序时,设置SO_REUSEADDR选项,并将本组的多播地址作为本地IP地址捆绑。

What is the difference between SO_REUSEADDR and SO_REUSEPORT?

from:UNIX Socket FAQ

SO_REUSEADDR allows your server to bind to an address which is in a

TIME_WAIT state. It does not allow more than one server to bind to the

same address. It was mentioned that use of this flag can create a

security risk because another server can bind to a the same port, by

binding to a specific address as opposed to INADDR_ANY. The

SO_REUSEPORT flag allows multiple processes to bind to the same address

provided all of them use the SO_REUSEPORT option.

From Richard Stevens (rstevens@noao.edu):

This is a newer flag that appeared in the 4.4BSD multicasting code

(although that code was from elsewhere, so I am not sure just who

invented the new SO_REUSEPORT flag).

What this flag lets you do is rebind a port that is already in use, but

only if all users of the port specify the flag. I believe the intent is

for multicasting apps, since if you're running the same app on a host,

all need to bind the same port. But the flag may have other uses. For

example the following is from a post in February:

From Stu Friedberg (stuartf@sequent.com):

SO_REUSEPORT is also useful for eliminating the try-10-times-to-bind

hack in ftpd's data connection setup routine. Without SO_REUSEPORT,

only one ftpd thread can bind to TCP (lhost, lport, INADDR_ANY, 0) in

preparation for connecting back to the client. Under conditions of

heavy load, there are more threads colliding here than the try-10-times

hack can accomodate. With SO_REUSEPORT, things work nicely and the hack

becomes unnecessary.

I have also heard that DEC OSF supports the flag. Also note that under

4.4BSD, if you are binding a multicast address, then SO_REUSEADDR is

condisered the same as SO_REUSEPORT (p. 731 of "TCP/IP Illustrated,

Volume 2"). I think under Solaris you just replace SO_REUSEPORT with

SO_REUSEADDR.

From a later Stevens posting, with minor editing:

Basically SO_REUSEPORT is a BSD'ism that arose when multicasting was

added, even thought it was not used in the original Steve Deering code.

I believe some BSD-derived systems may also include it (OSF, now

Digital Unix, perhaps?). SO_REUSEPORT lets you bind the same address

*and* port, but only if all the binders have specified it. But when

binding a multicast address (its main use), SO_REUSEADDR is considered

identical to SO_REUSEPORT (p. 731, "TCP/IP Illustrated, Volume 2"). So

for portability of multicasting applications I always use SO_REUSEADDR.

linux重用端口号,linux下 端口复用的问题相关推荐

  1. linux命令查询端口号,linux查询端口号(linux查看端口的命令)

    linux查询端口号(linux查看端口的命令) 2020-07-24 11:55:46 共10个回答 1.打开任务管理器(在桌面最下面的"任务栏"右击鼠标).2.在任务管理器界面 ...

  2. linux mysql 端口号_linux下mysql 查看默认端口号与修改端口号方法

    一.查看默认端口号 1.登录mysql [root@localhost ~]# mysql -uroot -p Enter password: 输入数据库密码: 2.使用show global var ...

  3. linux websphere 端口号,Linux环境下配置websphere7.0的一些命令

    Linux环境下配置websphere7.0的一些命令! 1.创建概要文件 通过命令行建立Dmgr服务器,进入${WAS_Home}/bin目录,运行 ./manageprofiles.sh -cre ...

  4. linux zookeeper 端口号,linux下zookeeper安装

    zookeeper安装需要依赖 jdk 或jre 1.下载jdk 2.解压jdk tar -zxvf jdk-8u221-linux-x64.tar.gz 3.配置jdk环境变量 export JAV ...

  5. linux对外开放端口号

    linux对外开放端口号 1.查询指定端口是否已经开启 firewall-cmd --query-port=8091/tcp 2.查看防火墙状态 查看防火墙状态 systemctl status fi ...

  6. 端口号,一个端口号是否可以被多个进程使用?

    1.端口号的作用 端口号可以用来标识同一个主机上通信的不同应用程序,端口号+IP地址就可以组成一个套接字,用来标识一个进程 2.端口号的应用场景 在TCP/IP协议中,用"源IP地址&quo ...

  7. linux snmp更改端口号,[Linux]Linux下修改snmp协议的默认161端口

    一.Linux SNMP的配置 SNMP的简介和Linux下IPV4,IPV6地址的snmp协议开启可以参考上一个随笔:[Linux]CentOS6.9开启snmp支持IPV4和IPV6 二.修改默认 ...

  8. linux activemq修改端口号,linux下 activemq集群配置

    1.简述:回想老王打电话讲故事案例. 2.优势:解耦,异步,横向扩展,顺序保障,安全可靠... 3.JMS(java message service),是java平台中关于面向消息中间件的API,用于 ...

  9. linux 影院 ftp客户端20端口号,Linux下的ftp客户端说明文档

    Linux下的ftp客户端说明文档 发布时间:2006-09-24 00:20:41来源:红联作者:userhq l 软件功能: 本程序基于linux下的socket函数,利用ftp 协议,实现lin ...

最新文章

  1. python怎样给对象赋值_Python对象赋值、浅拷贝和深拷贝
  2. python变量运算符_Python基础 — 变量和运算符
  3. linux 信号处理实验,linux下信号处理
  4. 新一代Hologres实时数仓大揭秘
  5. asp.net core的文件下载
  6. 我在 Go 圈儿里的几位老朋友
  7. 使用dotnet template快速开发Microsoft Teams Outgoing Web Hook
  8. 【深圳】掌通宝科技有限公司技术总监(兼架构师),约吗
  9. 通过OmniFaces缓存组件以编程方式缓存PrimeFaces图表
  10. 95-140-108-源码-transform-算子process
  11. python输入三个整数_python笔记3:依次输入3个数排序打
  12. 【工程项目经验】mac电脑lldb调试工具
  13. 跨浏览器(IE/FF/OPERA)JS代码小结
  14. 20.从0开始的微服务架构
  15. UOS声势浩大,麒麟没有反应
  16. vue 子页面调用父页面的参数_Vue子父组件间的数据传递
  17. 基于POP3协议收取邮件
  18. linux挂载光盘的命令,linux下挂载(mount)光盘镜像文件、移动硬盘
  19. linux下Intel无线网卡驱动安装
  20. Android中MVP模式

热门文章

  1. SQLyog无法连接mysql且不是因为未启动服务
  2. 01——LEF初稿2021-09-06下午
  3. 171103 Matlab subplot 用法
  4. 6266:取石子游戏
  5. HTML5andCSS3面试题大全
  6. matlab实现盖尔圆,一种结合四阶累积量与盖尔圆改进的信号源个数估计方法与流程...
  7. 方法返回多个值,使用Pair,Triple
  8. 做你自己,生活自然如你所愿燃烧吧,少年!
  9. 上海杉达计算机科学与技术面试内容,上海杉达学院自主招生面试试题综合素质答案技巧...
  10. 蓝桥-ALGO-40-会议中心