2

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

1

2 Answers 2

3

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

2
  • Does the program check for itself if some other program is listening to the port?
    – Wintermute
    Mar 3, 2011 at 20:33
  • The operating system does the check.
    – carson
    Mar 3, 2011 at 20:41
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.

2
  • What is it that prevents the application from binding to the port?
    – Wintermute
    Mar 3, 2011 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 3, 2011 at 21:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .