socket programming
Helge Aksdal
helge at aksdal.net
Tue Jul 19 14:42:05 EDT 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?
Trying xxx.xxx.xxx.xxx
telnet: connect to address xxx.xxx.xxx.xxx: Connection refused
Trying xxx.xxx.xxx.xxx
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.setblocking(0)
self.sock.connect((server, port))
(sread, swrite, serror) = select.select([], [self.sock], [], 10)
if swrite.count(self.sock) > 0:
i = self.sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
if 0 == i:
self.sock.setblocking(1)
--
Helge Aksdal
More information about the Python-list
mailing list