Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can sockets be used to connect multiple computers on different networks in python? [closed]

Tags:

python

sockets

I have been looking all over the internet for an answer but haven't been able to find one as of now. I am extremely new to networking so please do accept that I hardly know anything about it. I am able to send data to and from computers on a LAN network using sockets but I want to know if it is possible to connect to a computer at my friends house per say and send data to and from our computers solely using sockets (no telnet or netcat servers). Or is this impossible and should I be looking at a different python library or should I set up some sort of server which both machines would connect to?

Any help would be greatly appreciated and please take into account that I am new to this...

like image 230
cookies Avatar asked Aug 03 '15 11:08

cookies


1 Answers

Sockets should work, but there are some caveats:

  • If the server (assuming you are using TCP sockets) is behind a firewall or NAT (typically if you have a router) you will need it to be configured to redirect the port on the public interface (visible from the Internet) to the local port.
  • You will need to know your friend's public IP or hostname to connect to them.

If your networks look like this:

 +---------------+   +-----------+   +--------+   +---------------+   +------------------+
 | Your computer |-->|Your router|-->|Internet|-->|Friend's router|-->|Friends's computer|
 +---------------+   +-----------+   +--------+   +---------------+   +------------------+
   192.168.0.5       host.isp.com                  friend.isp.com       192.168.2.55

And your friend is running the server on his local network, on port 9000 (for example), then you'd connect to friend.isp.com:9000. If their router is configured to redirect traffic on port 9000 on the friend.isp.com interface (internet) to 192.168.2.55 (local machine) then a connection should be established correctly.

like image 200
André Laszlo Avatar answered Sep 25 '22 22:09

André Laszlo