Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when 2 computers listen to the same port and a router receives a packet through that port

What I am asking is if two computers listen to the same port and a packet of information enters the router through the WAN Ip and the same port. Would the packet go to both computers? Neither? One or the other?

IE

computer 1 -(internal IP)-> 192.168.1.3 -(listens to port)-> 4444

computer 2 -(internal IP)-> 192.168.1.2 -(listens to port)-> 4444

computer 3 -(connects and sends)-> 24.157.358.45:4444

packet -> computer 1 AND computer 2

The code in VB6 is:

LAN.LocalPort = 4444
LAN.Protocol = sckTCPProtocol
LAN.Listen

I am using a WinSock object in the Microsoft WinSock Control 6.0 in VB6 Professional

If there is something that needs to be clarified I would be more than happy to.

like image 673
user1822456 Avatar asked Nov 14 '12 01:11

user1822456


2 Answers

The router won't send an inbound packet to either machine unless communication has already been established.

If 192.168.1.3 calls out to some other machine (e.g. 4.5.6.7) from its port 4444, the router will assign an arbitrary port on its external address (say 24.157.358.45 [sic] :5555) and pass the packets on to 4.5.6.7. 4.5.6.7 will send reply packets to 24.157.358.45:5555 -- because that's the only address it knows about -- and the router will relay those to 192.168.1.3:4444.

That's the normal course of things, but there are a lot of additional details to this scheme that make it possible to establish communication with a machine behind a router via trickery.

The system of having machines with private IP addresses behind a router with a public address is called network address translation (NAT); it's a pretty deep topic.

like image 165
Russell Borogove Avatar answered Nov 03 '22 00:11

Russell Borogove


From my knowledge of routers, unless port forwarding is setup, the router will discard any packets sent on that port.

If port forwarding is setup, only one of the computers could be setup to receive the packets.

like image 26
CriticalImpact Avatar answered Nov 03 '22 00:11

CriticalImpact