0


ここで、serversocket を使用してポート x をリッスンしたいと同時に、ポート x を使用して他のサーバーソケットへのソケットを確立したいと考えています。つまり、serversocket があり、ソケットが 1 つの同じポートを使用することを意味します。
ソケットの場合、それは4つのタプルであり、1つのポートに複数のソケットを含めることができますが、ソケットとサーバーソケットの場合は?
ご清聴ありがとうございました!

4

1 に答える 1

4

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.

于 2011-11-13T21:18:00.540 に答える