am i correct in assuming that when a computer behind a router with port forwarding opens a port (port 1337, when i run my server), that the router automatically notices and sets itself up to send all port 1337 traffic to that computer?

i've got two simple applications, a client and a server. Bound to 127.0.0.1, the client finds the server just fine, but bind the server to the local network address (172.16.0.2) and aim the outgoing connection at the router (public) ip (from whatismyip.com), and the router denies the connection.
i suspect i just need to somehow tell the router that my computer is using port 1337, and that it should forward incoming traffic instead of denying it... or of course i could be hopelessly wrong. anyone, ideas?

#server
import socket
myip = socket.gethostbyname(socket.gethostname())
port = 1337
sock = socket.socket()
sock.bind((myip, port))
sock.listen(5)
print sock.accept()[1]

and

#client
import socket
server = "71.62.9.147"
port = 5132
sock = socket.socket()
sock.connect((server, port))
print "connected"

1) check firewall in your computer. this is not likely the case. but if you have a firewall set you have to open the port from your firewall too.
2) your router might not working correctly. That actualy happened to me. some routers have the port forwarding in their menu but it does not work. (if you are in the US. that is probably not the case.)
3) restart your router (don't ask :) )

if I were you I would try to forward some other port that you are sure , some app is listening to. for example I got ssh daemon listening to port 23 so I would try to forward port 23 and try connect to my computer with an ssh client. If I can connect to it , that means my network is fine.

I can not tell you what is wrong with your network but, those are the ways that I would follow to diagnose it. I hope that helps.

You may find your router has a 'virtual server' set up of some kind, if it has then it will allow you to add incoming requests to the list. This will give you the option to have you router watch the information coming on a sepecfic port then forward that request to the internal IP address and port you specify on any computer.

This is how I had my Python server set up, and it worked perfectly. Just remeber accessing the server internally and externally IS different, so test it from an external location.

Chris

This article has been dead for over six months. Start a new discussion instead.