Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 01 Dec 2014 04:23:47 -0800
From:      Yuri <yuri@rawbw.com>
To:        freebsd-net@freebsd.org
Subject:   Can multiple apps listen for TCP on the same port?
Message-ID:  <547C5DD3.90604@rawbw.com>

next in thread | raw e-mail | index | archive | help
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



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