From owner-freebsd-net@FreeBSD.ORG Mon Dec 1 12:23:56 2014 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 82558751 for ; Mon, 1 Dec 2014 12:23:56 +0000 (UTC) Received: from shell1.rawbw.com (shell1.rawbw.com [198.144.192.42]) by mx1.freebsd.org (Postfix) with ESMTP id 6D84A7B7 for ; Mon, 1 Dec 2014 12:23:55 +0000 (UTC) Received: from eagle.yuri.org (c-73-162-232-245.hsd1.ca.comcast.net [73.162.232.245]) (authenticated bits=0) by shell1.rawbw.com (8.14.9/8.14.9) with ESMTP id sB1CNm6H089752 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Mon, 1 Dec 2014 04:23:49 -0800 (PST) (envelope-from yuri@rawbw.com) X-Authentication-Warning: shell1.rawbw.com: Host c-73-162-232-245.hsd1.ca.comcast.net [73.162.232.245] claimed to be eagle.yuri.org Message-ID: <547C5DD3.90604@rawbw.com> Date: Mon, 01 Dec 2014 04:23:47 -0800 From: Yuri User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: freebsd-net@freebsd.org Subject: Can multiple apps listen for TCP on the same port? Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 12:23:56 -0000 I have a simple 'nc' based TCP server with shell script serving http protocol. But when I run the second instance, it never gets any connections and never fails. 'nc -l PORT' first calls listen with backlog=1 and socket option SO_REUSEADDR, and then calls accept. Once client is accepted, it closes the listening socket and only works with this connection. Why the second nc instance still never accepts any connections, once the first connection is accepted, and first listening socket is closed? When one listening socket is closed, shouldn't other listening sockets on the same port be accepting connections? It looks like the whole port is blocked without even having the listening socket on it by one alive connection (which after it was accepted doesn't have much to do with the original port). Yuri