I wrote a simple python script using the SocketServer, it works well on Windows, but when I execute it on a remote Linux machine(Ubuntu), it doesn’t work at all..
The script is like below:
#-*-coding:utf-8-*-
import SocketServer
class MyHandler(SocketServer.BaseRequestHandler):
def handle(self):
data_rcv = self.request.recv(1024).strip()
print data_rcv
myServer = SocketServer.ThreadingTCPServer(('127.0.0.1', 7777), MyHandler)
myServer.serve_forever()
I upload it to the remote machine by SSH, and then run the command python server.py on the remote machine, and try to access to xxx.xxx.xxx.xxx:7777/test with my browser, but nothing is printed on the remote machine’s teminal…any ideas?
UPDATE: Problem solved, it’s a firewall issue, thanks you all.
You are binding the server to
127.0.0.1, the IP address for localhost. This means the server will only accept connections originating from the same machine; it won’t recognize ones coming from another machine.You need to either bind to your external IP address, or bind to a wildcard address (i.e. don’t bind to any particular IP address, just a port). Try: