The existing launch XML files in /Library/LaunchDaemons or /System/Library/LaunchDaemons deserve study; from one of these and with some grepping about in /etc/services
$ grep 9100 /etc/services
hp-pdl-datastr 9100/udp # PDL Data Streaming Port
hp-pdl-datastr 9100/tcp # PDL Data Streaming Port
one might adapt one of the existing files to what I've saved to /Library/LaunchDaemons/cattery.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>com.exampe.cattery</string>
<key>ProgramArguments</key>
<array>
<string>/var/root/cattery</string>
</array>
<key>inetdCompatibility</key>
<dict>
<key>Wait</key>
<false/>
</dict>
<key>InitGroups</key>
<true/>
<key>Sockets</key>
<dict>
<key>Listeners</key>
<dict>
<key>SockServiceName</key>
<string>hp-pdl-datastr</string>
<key>SockType</key>
<string>stream</string>
</dict>
</dict>
</dict>
</plist>
Where /var/root/cattery here is the bad test script (what happens if clients connect two or more times per second?):
$ sudo cat /var/root/cattery
#!/bin/sh
cat > "/var/root/out.$(date +%s)"
$ sudo chmod +x /var/root/cattery
And then we enable our new service
$ sudo launchctl load -w /Library/LaunchDaemons/cattery.plist
And feed some test data to it
$ echo foo | nc localhost 9100
$ sudo find /var/root -name out\* -maxdepth 1
/var/root/out.1511845970
$ sudo cat /var/root/out.1511845970
foo
$
NOTE this code probably should not run as root, a
<key>UserName</key>
<string>_lp</string>
line as seen in /System/Library/LaunchDaemons/org.cups.cups-lpd.plist may help to not run the above as root, in which case the output directory for data saved must be writable by that user, and the program run executable (and perhaps also readable) by that user.