Pregunta

Me escribió un simple script en Python usando el SocketServer, funciona bien en Windows, pero cuando lo ejecuto en un equipo Linux remoto (Ubuntu), no funciona en absoluto .. El guión es como a continuación:

#-*-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()

Me subirlo a la máquina remota mediante SSH, y luego ejecute el comando python server.py en la máquina remota, y tratar de acceder a xxx.xxx.xxx.xxx:7777/test con mi navegador, pero nada se imprime en teminal de la máquina remota ... alguna idea?

ACTUALIZACIÓN:. Problema resuelto, es un problema de cortafuegos, gracias a todos

¿Fue útil?

Solución

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:

myServer = SocketServer.ThreadingTCPServer(('0.0.0.0', 7777), MyHandler) 

Otros consejos

You are binding to 127.0.0.1:7777 but then trying to access it through the servers external IP (I'll use your placeholder - xxx.xxx.xxx.xxx). 127.0.0.1:7777 and xxx.xxx.xxx.xxx:7777 are different ports and can be bound by different processes IIRC.

If that doesn't fix it, check your firewall, many hosts set up firewalls that block everything but the handful you are likely to use

Try with telnet or nc first, telnet to your public ip with your port and see what response you get. Also, why are accessing /test from the browser? I don't see that part in the code. I hope you have taken care of that.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top