1

My software need to listen to 2 different ports at the same time, I need something like that :

Client.Connect("127.0.0.1", 8001);
Client.Connect("127.0.0.1", 8002);

Is it possible ?

Alexus
  • 276
  • 1
  • 5
  • 22

1 Answers1

2

Not with a 1 connection, TCP Clients are connected individually so you need to make 2 port connection for multiple connectivity. For example, in Terminal you can't have multiple connection until you open a new window for second connection.

See Borealid answer on here, give you some clear view, but there is more to it.

Brief explanation:

For a stateful protocol (like TCP), a connection is identified by a 4-tuple consisting of source and destination ports and source and destination IP addresses. So, if two different machines connect to the same port on a third machine, there are two distinct connections because the source IPs differ. If the same machine (or two behind NAT or otherwise sharing the same IP address) connects twice to a single remote end, the connections are differentiated by source port (which is generally a random high-numbered port).

Community
  • 1
  • 1
Brian Nezhad
  • 6,148
  • 9
  • 44
  • 69
  • 1
    My software have two servers listening two devices, one server in TCP, the other in UDP mode. The UI application is listening to that two servers and displays the informations. I added another TcpClients and that seems to work. – Alexus Nov 19 '15 at 16:49