#tested with Python 3.1.1+ on Ubuntu 9.10 import socket import sys sock = socket.socket() sock.bind(("127.0.0.1", 12345)) sock.listen(5) #magic constant value from tcp server con = sock.accept() con = con[0] print(con.send(bytes("Hello", "ascii"))) print(con.sendall(bytes("Hello", "ascii"))) #PAUSE sys.stdin.read(1) # no run # ncat 127.0.0.1 12345 # and terminate connection after the 'HelloHello' arrived print(con.send(bytes("Hello", "ascii"))) # this returns 5, no error here #print(con.sendall(bytes("Hello", "ascii"))) # no error too con.close() sock.close()