How can I open a port (not application) in the macOS Sierra firewall?
To open a port you would use the following line(s):

pass in proto tcp from any to any port 40000
pass in proto tcp from any to any port 80
pass in proto {tcp, udp} from any to any port 53
pass in from any to any port 3601


To quick-start pf and open a port with one of the lines above use e.g.:

echo "pass in proto tcp from any to any port 40000" | sudo pfctl -ef -


To test the rule(s) use: sudo pfctl -s rules

After a reboot you would have to enter the command again, because pf is not started automatically.

By default the pf.conf file has no blocking all rule. So even after starting pf with sudo pfctl -e nothing is blocked.

If you don't want to dive deeply into pf/pf.conf/pfctl, I recommend to use a pfctl GUI like the free Murus Lite to configure pf.