From owner-freebsd-net@FreeBSD.ORG Mon Dec 1 15:57:29 2014 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 660A29DC for ; Mon, 1 Dec 2014 15:57:29 +0000 (UTC) Received: from fs.denninger.net (wsip-70-169-168-7.pn.at.cox.net [70.169.168.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "NewFS.denninger.net", Issuer "NewFS.denninger.net" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 01F2472 for ; Mon, 1 Dec 2014 15:57:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by fs.denninger.net (8.14.9/8.14.8) with ESMTP id sB1FbAHi000630 for ; Mon, 1 Dec 2014 09:37:15 -0600 (CST) (envelope-from karl@denninger.net) Received: from [127.0.0.1] (TLS/SSL) [208.54.85.211] by Spamblock-sys (LOCAL/AUTH); Mon Dec 1 09:37:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: BlackBerry Email (10.3.1.1154) Message-ID: <20141201153712.4304976.24709.1746@denninger.net> Date: Mon, 01 Dec 2014 10:37:12 -0500 Subject: Re: Can multiple apps listen for TCP on the same port? From: Karl Denninger In-Reply-To: <547C88AD.40407@rawbw.com> References: <547C5DD3.90604@rawbw.com> <20141201150225.GB64370@apollo.corbe.net> <547C88AD.40407@rawbw.com> To: Yuri , Daniel Corbe Cc: freebsd-net@freebsd.org X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Dec 2014 15:57:29 -0000 The second bind() call does fail but if the application ignores the return = code...=E2=80=8E. Are you sure all the associated system call return codes = are being checked? The right way to do this Imho =C2=A0is to have a parent process that calls = bind and listen, gets the notification of an incoming connection via select= () (allowing detection of exceptions as well) and then calls accept() and, = now having a connected file handle, fork()s and executes whatever is to han= dle the connection with the parent closing the handle so as to not orphan t= he handle when the child exits. =E2=80=8E --=C2=A0Karl (On=C2=A0Passport=C2=A0PDA)=E2=80=8E =C2=A0 Original Message =C2=A0 From: Yuri=E2=80=8E Sent: Monday, December 1, 2014 10:26 To: Daniel Corbe Cc: freebsd-net@freebsd.org Subject: Re: Can multiple apps listen for TCP on the same port? 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=20 instance isn't listening any more. The listening socket was closed. Why=20 the presence of the socket that was accepted from (now closed) listening=20 socket in the first instance is considered "occupying it"? Actually no system call in the second instance ever fails. Yuri _______________________________________________ freebsd-net@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-net To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" %SPAMBLOCK-SYS: Matched [@freebsd.org+], message ok