Search code examples
pythonp2p

How to build a Python p2p application?


I am new to Python programming and have covered sockets a bit. I couldn't find any simple implementation on the web. Its basic functionality should cover:

  • simple chat
  • file sharing
  • peer lookup

How do I start, and what should be the p2p model? I don't want to use any library such as Twisted, as it is complex.


Solution

  • You could write the library yourself, if you're willing to work with sockets directly. Have each node contain a list of peers that is regularly updated, and set each node to advertise its presence to a central server. You'd need to look into network traversal algorithms, hash tables, etc but it could be done. As Xavier says, start simple first, and get it working quickly - then add features.

    For simplification you could implement manual peering to start with; get file sharing and chat working first, and then add peering/discovery later.

    There is quite a bit of work here but it may be more achievable if you've written everything - everything is easier to understand! But, the upside of a library is a lot of the work is done for you. It's a trade-off :)