Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 01 Dec 2014 07:26:37 -0800
From:      Yuri <yuri@rawbw.com>
To:        Daniel Corbe <corbe@corbe.net>
Cc:        freebsd-net@freebsd.org
Subject:   Re: Can multiple apps listen for TCP on the same port?
Message-ID:  <547C88AD.40407@rawbw.com>
In-Reply-To: <20141201150225.GB64370@apollo.corbe.net>
References:  <547C5DD3.90604@rawbw.com> <20141201150225.GB64370@apollo.corbe.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On 12/01/2014 07:02, Daniel Corbe wrote:
> Generally the answer to your question is no.  Two applications cannot
> occupy the same port on the same protocol at the same time.
>
> To expand on this answer and to hopefully shed some light on why the
> behavior you're observing with your application is absolutely correct;
> the calling application (in this case, nc) has to explicitly call bind(2)
> before it can begin accepting connections.  If that port is already in
> use then the call to bind(2) will fail.  And in your case I suspect nc
> is simply choosing to silently fail.

Here the question is what does it mean "occupy the port"? The first 
instance isn't listening any more. The listening socket was closed. Why 
the presence of the socket that was accepted from (now closed) listening 
socket in the first instance is considered "occupying it"?

Actually no system call in the second instance ever fails.

Yuri



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?547C88AD.40407>