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, the client finds the server just fine, but bind the server to the local network address ( and aim the outgoing connection at the router (public) ip (from, 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?

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


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

Recommended Answers

All 2 Replies

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.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.