多个进程能同时监听一个端口吗?

ImAmelie 2017-08-11 06:55:28


我知道那个SO_REUSEADDR是在线程关闭没释放的时候直接重新监听的

但是看到了这个回答后感觉很困惑



哪里理解不对请指出

强调一下问题:
多个进程能※同时※监听同一端口吗?

多个socket能※同时※监听同一端口吗?
...全文
1415 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wensuliang 2017-08-30
  • 打赏
  • 举报
回复
当TCP执行一个主动关闭,并发回最后一个ACK,该连接必须在 TIME_WAIT状态停留的时间为 2倍的MSL。这样可让 TCP再次发送最后的ACK以防这个ACK丢失(另一端超时并重发最后的FIN)。这个期间socket不能被使用,但是在服务需要处理大量请求时,为提高服务器的吞吐率,可以设置SO_REUSEADDR重用TCP状态为TIME_WAIT的socket
ForestDB 2017-08-12
  • 打赏
  • 举报
回复 1
SO_REUSEPORT (since Linux 3.9) 内核3.9 Permits multiple AF_INET or AF_INET6 sockets to be bound to an identical socket address. 允许多个IP或者IPv6的socket绑定到同一个socket地址。 This option must be set on each socket (including the first socket) prior to calling bind(2) on the socket. 该选项必须在调用bind之前设置到每个socket上(包括第一个socket)。 To prevent port hijacking, all of the processes binding to the same address must have the same effective UID. 为了防止劫持,绑定到同一地址的所有进程要有相同的EUID。 This option can be employed with both TCP and UDP sockets. TCP和UDP socket都可以使用该选项。 For TCP sockets, this option allows accept(2) load distribution in a multi-threaded server to be improved by using a distinct listener socket for each thread. 对TCP socket,该选项可以改善多线程服务器中的accept负载分发,通过给每一个线程一个不同的监听socket。 This provides improved load distribution as compared to traditional techniques such using a single accept(2)ing thread that distributes connections, or having multiple threads that compete to accept(2) from the same socket. 比起传统的做法,比如用单一的线程来分发连接,或者在多线程中accept相同的socket来竞争,该选项可以改善负载分发。 For UDP sockets, the use of this option can provide better distribution of incoming datagrams to multiple processes (or threads) as compared to the traditional technique of having multiple pro‐ cesses compete to receive datagrams on the same socket. 对UDP socket,使用该选项可以提供更好的多进程/线程中的数据包分发;传统的做法是多进程在同一个socket上竞争接受数据包。
ImAmelie 2017-08-12
  • 打赏
  • 举报
回复
老哥,能简单的翻译一下吗?
引用 2 楼 ForestDB 的回复:

       SO_REUSEPORT (since Linux 3.9)
              Permits  multiple  AF_INET  or  AF_INET6  sockets to be bound to an identical socket address.  This
              option must be set on each socket (including the first socket) prior  to  calling  bind(2)  on  the
              socket.   To prevent port hijacking, all of the processes binding to the same address must have the
              same effective UID.  This option can be employed with both TCP and UDP sockets.

              For TCP sockets, this option allows accept(2) load distribution in a multi-threaded  server  to  be
              improved  by using a distinct listener socket for each thread.  This provides improved load distri‐
              bution as compared to traditional techniques such using a single accept(2)ing thread that  distrib‐
              utes connections, or having multiple threads that compete to accept(2) from the same socket.

              For  UDP  sockets,  the use of this option can provide better distribution of incoming datagrams to
              multiple processes (or threads) as compared to the traditional technique of  having  multiple  pro‐
              cesses compete to receive datagrams on the same socket.
ForestDB 2017-08-11
  • 打赏
  • 举报
回复

       SO_REUSEPORT (since Linux 3.9)
              Permits  multiple  AF_INET  or  AF_INET6  sockets to be bound to an identical socket address.  This
              option must be set on each socket (including the first socket) prior  to  calling  bind(2)  on  the
              socket.   To prevent port hijacking, all of the processes binding to the same address must have the
              same effective UID.  This option can be employed with both TCP and UDP sockets.

              For TCP sockets, this option allows accept(2) load distribution in a multi-threaded  server  to  be
              improved  by using a distinct listener socket for each thread.  This provides improved load distri‐
              bution as compared to traditional techniques such using a single accept(2)ing thread that  distrib‐
              utes connections, or having multiple threads that compete to accept(2) from the same socket.

              For  UDP  sockets,  the use of this option can provide better distribution of incoming datagrams to
              multiple processes (or threads) as compared to the traditional technique of  having  multiple  pro‐
              cesses compete to receive datagrams on the same socket.
ForestDB 2017-08-11
  • 打赏
  • 举报
回复
如果SO_REUSEPORT的描述无误的话,那么,可以,可以。

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧