问题
Is it possible in TCP for different processes not sharing the same executable image (so no fork()
for example) to use a same client-side port on Windows, Linux or OSX? This is specifically related to the socket options SO_REUSEADDR
and SO_REUSEPORT
set using setsockopt()
I believe.
As far as I've read, I believe it is possible for the same process/image to do this, but I haven't found information as to multiple processes/images. I would imagine it is theoretically possible since each socket is defined by the 5-valued tuple [IP_PROTO, src_ip:src_port, dst_ip:dst_port]. So I would assume that, as long as multiple TCP connections sharing a client-side port are not made to the same dst_ip:dst_port, this would be theoretically possible.
回答1:
UDP is not connection-oriented and has no real distinction between client and server, so for UDP this question doesn't make a lot of sense.
For TCP, you can use SO_REUSEADDR to bind mulitple clients to the same port, but why would you want to? Normally you leave the client unbound before making a connection and let the kernel pick an unused port for you.
来源:https://stackoverflow.com/questions/41788786/tcp-possible-for-same-client-side-port-to-be-used-for-different-connections-by