The server listens for messages, and the client sends messages.
The server must be started before the client, otherwise the client will not connect.
References
Good easy guide for simple TCP chat server.
I didn't have to make any firewall changes to get this to work, so don't mess with ufw.
ufw can mess up existing connections like ssh.
IANA port registration list:
Wikipedia port registration list:
Bash Commands
TCP
# Server (IP = 1.2.3.4):
# Listen for TCP messages on port 5169 (machine IP = 1.2.3.4)
netcat -l -p 5169
netcat -lt -p 5169 # Equivalent
nc -l -p 5169 # Equivalent
nc -lt -p 5169 # Equivalent
# Client (any IP on network):
# Send TCP messages to port 5169 of machine 1.2.3.4 (from any IP on same network)
netcat 1.2.3.4 5169
netcat -t 1.2.3.4 5169 # Equivalent
nc 1.2.3.4 5169 # Equivalent
nc -t 1.2.3.4 5169 # Equivalent
UDP
# Server (IP = 1.2.3.4):
# Listen for UDP messages on port 5170 (machine IP = 1.2.3.4)
netcat -lu -p 5170
nc -lu -p 5170 # Equivalent
# Client (any IP on network):
# Send UDP messages to port 5170 of machine 1.2.3.4 (from any IP on same network)
netcat -u 1.2.3.4 5169
nc -u 1.2.3.4 5169 # Equivalent