Code Monkey home page Code Monkey logo

pypunchp2p's Introduction

PyPunchP2P

Python p2p chat client/server with built-in NAT traversal (UDP hole punching).
I've write an article about the detailed implementation (in Chinese).

Based on
koenbollen's gist
pystun
Peer-to-Peer Communication Across Network Address Translators

Python edition: py2.6+ but no Python 3 support
Platform: Linux/Windows

Usage

Suppose you run server.py on a VPS with ip 1.2.3.4, listening on port 5678

$ server.py 5678

On client A and client B (run this on both clients):

$ client.py 1.2.3.4 5678 100  

The number 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.

Test Mode

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 1.2.3.4 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.

License

MIT

pypunchp2p's People

Contributors

laike9m avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.