You do it with the -k option to nc.
-k Forces nc to stay listening for another connection after its cur-
rent connection is completed. It is an error to use this option
without the -l option. When used together with the -u option,
the server socket is not connected and it can receive UDP data-
grams from multiple hosts.
Example:
$ rm -f /tmp/socket # unlink the socket if it already exists
$ nc -vklU /tmp/socket # the server
Connection from mack received!
yes
Connection from mack received!
yes
...
It's recommended to unlink() the socket after use -- but, in fact, most programs check if it exists and remove it before calling bind() on it; if the socket path exists in the filesystem and you try to bind() to it, you will get an EADDRINUSE error even when no program is using it in any way.
One way to avoid this whole mess on linux is to use "abstract" unix sockets, but they don't seem to be supported by netcat.
ncyou are trying to have a "server" listening on the socket while something else is already listening to it. In the first case, a singleacpidinstance is listening on the socket. In both cases, multiple clients can write to it. (All this written with an appropriate amount of handwaving).ncallows only single-use sockets. What's true, is thatncis not a real server (it will notforka subprocess to handle a connection, then go back to accepting connections while the child is still running, like eg. the X11 server oracpiddo); whilenc -lis handling a connection, it will notaccept()other connections on the same socket. And this is no different from hownc -lworks withtcpsockets.ncprocess just to allow multiple other listeners ?