Question:
Python Network Question: How can I get my client to connect over the net?
?
2013-02-18 06:53:39 UTC
I followed a pretty basic tutorial on Sockets, and wrote a small script that allows me to connect over LAN to another computer, and I can connect to myself on my own computer (Little pointless)

The problem is that I need it to connect over the internet to the client piece of software I wrote. Except the client can never find my connection.

This is where I get confused, he obviously cannot enter in my local IP, as it doesn't exist on his network. He's going to have to use my routers external IP.

But then how, will the client be able to know which computer to connect to when he enters the external IP of my network, there could be 3-4 different computers on it.

I have it so that I define the port he is to connect over, except despite having the same ports entered in, nothing worked.

Can someone help?
Four answers:
husoski
2013-02-18 07:40:16 UTC
The server side must be reachable from the Internet. The details depend on how the server is connected. If it's on a DSL/cable modem, directly connected without a router, then all you need is to know your IP address and use a port that's not blocked by either your internet provider, or by firewall software on your computer. If that's your setup, check your firewall settings to make sure that incoming connections on that port are allowed. Even if it's not your setup, you still need to do that if you run a firewall.



If you use a router (most people do, these days, if only for the wireless), then that is a computer that acts as the primary network device attached to your modem. It redirects all traffic from computers in your home through that one IP address.



Outgoing client connections are handled transparently. The router has the local IP/port of the client from the connect request, plus the Internet IP/port of the server and can translate packets on the fly. (That's called Network Address Translation, or NAT.) All home routers are NAT routers.



Inbound connections are different because the router only sees its IP address plus a port number. That's not enough information to send packets to the correct computer on your home network. You supply the information with "port forwarding", which nearly all home routers support. Sometimes it is given a different name (I had a GigaFast for years that called it "virtual server"). Go to your modem's setup page with a browser and look around.



There's often an option to set up a default computer to receive all incoming request not explicitly forwarded elsewhere. (For no obvious reason, it's called a "DMZ" by some modems.) Use that with care, if at all, since that exposes every open port on the "DMZ" computer to the Internet. You've just lost the "hardware firewall" function of the router on that computer, so a software firewall is a Real Good Idea. Better is to just forward the ports or port ranges you need.



For specifics, check the router docs, or web search for "port forward" plus your router name and model. Also check docs for "firewall settings" on your OS version or distro.
Daniel R
2013-02-18 06:59:18 UTC
This isn't really a Python question.



You'll need to configure your tier to forward that port to the right computer. Pretty much all routers have an option to do this somewhere on their admin interface.
Kaydell
2013-02-18 21:59:04 UTC
@husoski seems quite knowledgable about getting your Python program be be available over the Internet.



You could redevelop your code to work from a web-host on the Internet. My web hosting service says that they support Python.
2014-07-30 11:37:18 UTC
Well

The most famous peer to peer program for file sharing is Emule. If you dont have it you find it here http://bit.ly/1Aymdaz

Give it a try.

Hope it helps.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...