yaobinwen / robin_on_rails

Robin on Rails: my notes about technology and some other knowledge.
1 stars 0 forks source link

Figure out why `nc` allows two instances to listen to the same `address:port` #177

Closed yaobinwen closed 1 year ago

yaobinwen commented 1 year ago

Description

On my machine:

But I remember TCP doesn't allow listening to the same address/port at the same time. What's going on?

TODO

yaobinwen commented 1 year ago

Update (2023-07-10)

So this answer tells why:

So the socket is setup with the options SO_REUSEADDR and SO_REUSEPORT, which allow multiple processes to bind to the same port and same listening address. ... The goal of this option is to allow an easy form of load balancing: incoming connections to the port will be redirected to one of the processes (apparently at random).

This answer also recommends the detailed answer here. But this detailed answer provides so much information that I need to study further in another session.