I'm trying to create a Python program that will listen on a socket. I'm using Windows 7 with Python 2.7. Whatever I do, the socket seems to be accessible from the local machine but not from elsewhere on the network.
I've got the following code:
from werkzeug.wrappers import Request, Response @Request.application def application(request): return Response('Hello World!') if __name__ == '__main__': from werkzeug.serving import run_simple # Using empty string or the machine's real IP address here # gives the same problem run_simple('0.0.0.0', 4000, application) If I connect from the local machine I see the response fine. If I execute
$ curl 'http://192.168.1.1:4000/' from another (linux) box on the network, the curl hangs for a long time before timing out. Wireshark shows that I receive a SYN packet to port 4000 but don't see it ACKed.
I've tried making sure packets to this port are allowed through the firewall (the fact that I see the SYNs in Wireshark suggests this is not the problem). I've tried setting Python to run as administrator (and I've checked that ctypes.windll.shell32.IsUserAnAdmin() returns true). This isn't just Werkzeug, I've tried with SocketServer from the Python standard library as well.
Running Windows Apache on the same port works fine from across the network, which suggests there's no problem with the network or firewall or with my curl request.
netstat -an shows:
TCP 0.0.0.0:4000 0.0.0.0:0 LISTENING Edit: I've tried with the following minimal code. On the server side (Windows 7):
import socket s = socket.socket() s.bind(('', 8080)) s.listen(1) remotesock, addr = s.accept() And on the linux client:
import socket s = socket.socket() s.connect('192.168.1.1', 8080) This hangs until timeout, as with the curl.
python.exeto the firewall exception list.