Q:

Why can't I connect two sockets?

I am writing client code that deals with data streams coming from two servers A & B.  All three nodes are on the same local subnet.  I'm trying to create two sockets defined as described below.
Socket description= [local/client IP]:[local/client port]:[remote/server IP]:[remote/server port]
Socket to connect to A: [192.168.40.10]:[50002]:[192.168.40.60]:[50002]
Socket to connect to B: [192.168.40.10]:[50002]:[192.168.40.61]:[50002]
When I attempt to open the second socket, I get an exception that "each socket address a.k.a. protocol/network address/port can be used only once".  I thought I could define a different socket since the remote IP address is different even though the local IP address and port number are the same.  Do I have no choice but to consume both data streams through the same socket?

A:

You cannot use the same local port of your machine twice at the same time. You could open another socket (with another port number, e.g. 50003) at you local machine, and connect to remote socket on [192.168.40.61]:[50002].

