Linux basic Peer to Peer Python code

Spread the word!

I tested it on Ubuntu 17.10 in my local network.

On webcodegeeks.com (here the link) I found one of the most simple working code about peer to peer communication to execute in the terminal. When running codes like this there is a common problem: if the program crashes or is just closed using Ctrl+Z the socket will not be closed properly and on the next code execution there will be displayed an error telling us that a process is already listening on that address. To avoid this I just added a line to make python executing a bash code which kills any process listening at that port.

Beside this, I just personalized a bit the program presentation by making the sender and the receiver’s ip address being passed as parameters on the terminal line. It means, the command to execute the program follows this syntax:

The resulting code:

Type in your terminal the following line (and press Enter) to get the program:

SAMPLE PROCEDURELet’s assume now you want to “easily” p2p communicate with someone. The following procedure describes a possibility to achieve this as fast as possible. Note: also your chat partner should follow the same procedure!

  1. Type in your terminal the following line (and press Enter) to get the program:


  2. Go here and follow the instructions to set a nickname for your p2p communication and find your chat partner’s nick.
  3. To end the communication just use Ctrl+Z

Be the first to comment

Leave a Reply

Your email address will not be published.


*