THIS PROJECT IS FOR STUDYING AND VERIFICATION, DON'T USE IT IN PRODUCTION.
Python p2p chat client/server with built-in NAT traversal (UDP hole punching).
I've written an article about the detailed implementation (in Chinese).
Python edition: py2.6+ but no Python 3 support
Suppose you run server.py on a VPS with ip 220.127.116.11, listening on port 5678
$ server.py 5678
On client A and client B (run this on both clients):
$ client.py 18.104.22.168 5678 100
100 is used to match clients, you can choose any number you like but only clients with the same number will be linked by server. If two clients get linked, two people can chat by typing in terminal, and once you hit
<ENTER> your partner will see your message in his terminal.
Encoding is a known issue since I didn't pay much effort on making this tool perfect, but as long as you type English it will be fine.
You could do simulation testing by specifying a fourth parameter of
client.py, it will assume that your client is behind a specific type of NAT device.
Here are the corresponding NAT type and number:
FullCone 0 RestrictNAT 1 RestrictPortNAT 2 SymmetricNAT 3
So you might run
$ client.py 22.214.171.124 5678 100 1
pretending your client is behind RestrictNAT.
You can test the relay server functionality by making
3 as the forth parameter, since if one client is behind symmetric NAT, there will be no direct connection but server forwaring.