TCP - possible for same client-side port to be used for different connections by different applications simlutaneously?

一世执手 提交于 2021-02-08 09:25:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!