Search code examples
pythonipcommunication

Make 2 PCs communicate with each other without a local network


I use python and the socket library to allow communication between 2 PCs. In a local network, everything works perfectly! But now I'm looking to be able to communicate outside my local network... I've been looking on the internet and I've found explanations: you have to create a dmz on my router or do a port forwarding on my router, etc. I was wondering if there was an easier way than to modify my router and how did the instant messengers such as Signal, Skype work? Because for these applications I do not need to modify my router? Sorry for the mistakes, I don't speak English. Small precision I am only 15 years old please be indulgent. Thanks !

My goal here is to retrieve on pc#1 the keyboard keys that are pressed and transfer them to pc#2 with a latency really of the order of a few milliseconds only.


Solution

  • Routers have whats called a N.A.T. (Network Address Translation) each time you send something to a server a "hole" is opened on the NAT allowing you to receive packets from the server you sent something to. (The server accepts packets on one port that's forwarded from their router).

    When using skype you send your message to the skype server, the skype server stores it, and then the other person asks the skype server if it has any messages for him, since he stored your message he sends it to him as a response.

    This is what a Server-Client Model Is.

    Direct communication (peer to peer) is more complicated and requires more roundabout methods such a UDP Hole punching or other NAT traversal methods.

    This question might also help How to communicate between two machines with public IP but both behind LAN(python solution)?