Can two applications listen to the same port?

The short answer is “no, not on the same host."

The longer answer is that this is by design, the basic rationale being consistency. Consider what would happen if two different applications were able to listen on the same port: first of all, there is no guarantee that those two applications would provide the same service, or even speak the same protocol to connecting clients; furthermore the operating system would need to make decisions about how to distribute clients among the listening applications.

The only time it would make sense to have multiple applications listening on the same port is if a single application were not sufficient to service all the incoming requests. A simple solution would be to run multiple instances of the application in parallel, but the design of TCP forces a single application to handle such parallelism itself. Applications generally do so by having a single task dedicated to accepting incoming connections and, for each accepted connection, allocating resources to service it. (This may be done by launching a new coroutine or thread; the latter is generally too heavyweight an approach, and thread-based designs are more likely to simply assign the connection to one of an existing pool of worker threads.)


Blog: Cloudy with a Chance of TCP Drops