Server and Client Socket problem

Pierre Quentel quentel.pierre at wanadoo.fr
Sat Jan 24 08:42:32 CET 2004


Apart from indentation, you had forgotten the "try" statement in client
This should work better :

Client

---------------------
import socket

def run():
    try:
        cliente = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        cliente.connect(('localhost', 6969))
    except:
        print "No he podido Conectar con el Servidor"
        return
    datos = '12345678'
    cliente.send(datos)
    #cliente.close()

run()

---------------------

Server

---------------------
import socket

def run():
    servidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    servidor.bind(('localhost', 6969))
    servidor.listen(1)
    while 1:
        (conexion, direccion) = servidor.accept()
        datos = conexion.recv(4069)
        print "Servidor Recibe", datos
        if datos == "quit":
            servidor.close()
            break

run()
---------------------

@+
Pierre





More information about the Python-list mailing list