socket programming

Helge Aksdal helge at
Tue Jul 19 20:42:05 CEST 2005

i've recently made my very first socket program in python,
however i've stumbled upon a problem.

this program connects to a server serveral hundred time while it's
executed (it's not possible to let connection stay up, because the
server closes it), and after a time my program dies with the error:
"socket.error: (134, 'Transport endpoint is not connected')"

if i then change to a console window, and telnet to this server it
sends me to another one. That's probably why my program dies, how
can i get my code to handle this?

telnet: connect to address Connection refused
Connected to xxxxxx.xxxxx.
Escape character is '^]'.

here is my current connection code:

def connect(self, server, port):
    self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.sock.connect((server, port))
    (sread, swrite, serror) =[], [self.sock], [], 10)
    if swrite.count(self.sock) > 0:
        i = self.sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        if 0 == i:

Helge Aksdal

More information about the Python-list mailing list