2

Wat happens if two applications try to listen to the same port?

Wintermute
  • 375
  • 2
  • 5
  • 12

2 Answers2

5

Unless they are spawned via tcpmux, the first application binds to the port and listens for connections to it, while the second one cannot bind and cannot listen.

adamo
  • 6,925
  • 3
  • 30
  • 58
  • What is it that prevents the application from binding to the port? – Wintermute Mar 03 '11 at 20:36
  • When your application makes the relevant system call to "grab" the port, the operating system will "inform" it (via a relevant error code) that it is already taken. – adamo Mar 03 '11 at 21:17
3

The second one that binds to the port will get an error saying something else is already listening on the port.

carson
  • 1,630
  • 11
  • 15