socket programming

H

Helge Aksdal

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)
 
G

Grant Edwards

if i then change to a console window, and telnet to this
server it sends me to another one.

What do you mean "sends me to another one"?

The telnet protocol doesn't have any sort of "redirect"
capability.
That's probably why my program dies, how can i get my code to
handle this?

I don't understand what "this" is. If the server is sending
you some sort of redirect message, then parse it and obey it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top