Now I want to use a serversocket to listen port x, in the same time I want to use the port x to establish a socket to other serversocket, that means there is a serversocket and a socket will use one same port, is that possible?
I know for socket, it is four tuple, one port can have multiple socket, but for a socket and serversocket?
thank you for your attention!
Now I want to use a serversocket to listen port x, in the same
Share
It’s hard to understand your question because it’s not clear when you say “port” whether you mean source port or destination port.
If your question is, “Can I accept inbound connections on port X and also make outbound connections to port X?” The answer is yes. (You can bind to and connect to the same port.)
If your question is, “Can I listen on port X and also make outbound connections from port X?” The answer is no — unless you use two different local IP addresses. For TCP on a single IP address, you can only bind to the port once. If you bind to listen, from then on, the port is reserved for the incoming connections you will accept — you cannot bind to it again to make outgoing connections from it.