Título: Problema con puertos de escucha en Python Publicado por: jojoesyoyo en 6 Marzo 2006, 04:57 am Hola, estoy scribiendo un servidor en python(linux-debian), para un nuevo protocolo inventado por mi (quiero experimentar). El servidor escucha en el puerto 1864, que he verificado que está disponible para uso. Cuando intento conectarme (desde mi misma computadora) al servidor:
Código: >>> soc.connect(('localhost', 1864)) Esto functiona perfectamente, y tambien el envio y recepcion de mensajes. Mi problema es cuando intento acceder al mismo servidor desde otra computadora (de la red local): Código: >>> soc.connect(('192.168.1.2', 1864)) #192.168.1.2 es mi ip local No sé que pasa. He verificiado en iptables, y todo está aceptado, nada está bloqueado.Traceback (most recent callback) File "<stdin>", line 1, in ? File "<string>", line 1, in connect socket.error: (10061, 'Connection refused') Uso un modem para conectar la red local a internet. Tengo Debian-31r0a, mi arquitectura es i386. Mi version de python es 2.3.5 y 2.4.2 (tengo los dos instalados para probar). La otra computadora de la red local que uso para probar tiene Windows 98 con Python 2.4.2, su ip es 192.168.1.3. También he probado con gmailftpd.py y smtpd.py, y tengo el mismo problema. Mi servidor (está basado en gmailftpd.py, de libgmail para python): usa una clase derivada de asyncore.dispatcher como servidor, y otra clase derivada de asynchat.async_chat como canal (conexion hacia un 'cliente') Acá posteo la parte del codigo en el que se inicializa el servidor, y tmb en el que se inicia el canal hacia un 'cliente'. Código: class NEAIMChannel(asynchat.async_chat): """This is only a channel of the NEAIMServer""" def __init__(self, server, conn, addr): """Method that runs when a new NEAIMChannel is created.""" # Run parent's __init__ method. asynchat.async_chat.__init__(self, conn) # Set object constants and variables self.__server = server # NEAIMServer self.__conn = conn # Connection from the addr to NEAIMServer self.__addr = addr # Address of the client self.__line = [] # Buffer for the commands self.__fqdn = socket.getfqdn() # Fully qualified domain name of localhost ?? self.__peer = conn.getpeername() # Remote endpoint address self.__cver = __version__ # Client version, is by default the same as the # server, the client can change it by sending'VI x.x' # Print to DEBUGSTREAM the peername print >> DEBUGSTREAM, 'Peer:', repr(self.__peer) # Set terminator for the commands (new line is only \n) self.set_terminator('\r\n') # The channel is initialized, add it to the list channels.append(self) # The 'welcome' message (Version Info) self.push('VI %s' % __version__) # [...] # class NEAIMServer(asyncore.dispatcher): """The real NEAIMServer, it handles all requests and creates NEAIMChannel's""" def __init__(self, localaddr): """Method that runs when a new NEAIMChannel is created.""" # Set object constants and variables self._localaddr = localaddr # Local address # Run parent's __init__ method asyncore.dispatcher.__init__(self) # Create a socket self.create_socket(socket.AF_INET, socket.SOCK_STREAM) # Try to re-use a server port if possible self.set_reuse_addr() self.bind(localaddr) self.listen(5) # Print to DEBUGSTREAM that the server is started, and the local address and port. print >> DEBUGSTREAM, \ '%s started at %s\n\tLocal addr: %s\n' % ( self.__class__.__name__, time.ctime(time.time()), localaddr) # def handle_accept(self): """Called when a new client attepts to connect""" # Accept the connection, get socket for connection and address conn, addr = self.accept() # Print to DEBUGSTREAM that there's an incoming connection, and the info print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr) # Create a new channel for the connection channel = NEAIMChannel(self, conn, addr) # # # Si estamos en __main__ if __name__ == '__main__': # Set DEBUGSTREAM DEBUGSTREAM = sys.stderr # Create server proxy = NEAIMServer(('127.0.0.1', 1864)) # Create channels array channels = [] # Do a infinite loop listening try: asyncore.loop() except KeyboardInterrupt: pass Por si acaso, también tengo un servidor web (apache) instalado en mi computadora, y funciona perfectamente. Gracias de antemano a los que me respondan... |