A P2P application with Python

I’m not exactly sure if a P2P system is necessary for the project requirements, however…

A P2P system doesn’t have separate client and server applications but instead there is a single application that acts both as a client and server. In a sense, the application acts as a client because it reaches out to a server and it acts as a server because it accepts queries/commands from a client.

http://cs.berry.edu/~nhamid/p2p/framework-python.html shows how to construct a simple p2p in Python. This example makes a loop to accept connections coming in (other peers) and spawns a thread to handle the incoming connection. It also has the structure in place to send messages back to logged peers.

A big problem is how a peer will locate other peers and this is usually handled through third party, such as a dedicated “coordination”/”bootstrap” server that can point a peer to at least another peer (which from there could ask that peer for more peers). Your project might not need that considering you already know the address your peer will use to connect to another peer.

Referencing the website above, you would make a handler function and place it in self.handlers. Since that function would be passed the incoming peer’s information you could make the application send back the data you wish (the address to connect to)