socket programming
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 xx.x. 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: socket programming
* Jaime Wyant <[EMAIL PROTECTED]> [2005/07/19 21:26]: > It sounds really strange to connect to a server "several hundred" > times. If I had to guess, the server monitored all of the connects > coming from your IP address and eventually stopped accepting ANY > connections. That's really what it eventually does, just that it refuses my connection, and a connection to another server is established. The alternative is to do it by http connection, but i'm afraid that's going to be too slow. or am i wrong here? To help you understand me better, this is a server at work that gives me some account information, so when i want to check "several hundred" accounts i need to look them up one by one since the server closes the connection after each query. -- Helge Aksdal -- http://mail.python.org/mailman/listinfo/python-list
Re: socket programming
* Terry Reedy <[EMAIL PROTECTED]> [2005/07/19 22:57]: > Ask your server administrator if you are bumping up against a hidden > connection limit. Or if a query can ask about multiple accounts. how can i use a connection limit to my advantage? i know for certain that a query can't ask about multiple accounts. -- Helge Aksdal -- http://mail.python.org/mailman/listinfo/python-list
Re: socket programming
* Jaime Wyant <[EMAIL PROTECTED]> [2005/07/19 23:09]: > I don't think you can use a limit to your advantage. If you are > bumping against some limit and you can't query for multiple accounts > then there doesn't seem to be much you can really do. The problem would be solved, if i just could get my socket code to follow the redirection, as i tried to explain in my first email. any tips? or do i have to use good old nasty time.sleep to avoid this? -- Helge Aksdal -- http://mail.python.org/mailman/listinfo/python-list
Re: socket programming
* gry@ll.mit.edu [2005/07/20 15:26]: > What I have done in similar circumstances is put in a random sleep > between connections to fool the server's load manager. Something like: > > .import time > .min_pause,max_pause = (5.0, 10.0) #seconds > .while True: > . time.sleep(random.uniform(min_pause, max_pause)) > . do_connection_and_query_stuff() > > It works for me. Just play with the pause parameters until it fails > and add a little. thanks for the tip. i'll give that a shot. -- Helge Aksdal -- http://mail.python.org/mailman/listinfo/python-list
Re: socket programming
* gry@ll.mit.edu [2005/07/20 15:26]: > What I have done in similar circumstances is put in a random sleep > between connections to fool the server's load manager. Something like: > > .import time > .min_pause,max_pause = (5.0, 10.0) #seconds > .while True: > . time.sleep(random.uniform(min_pause, max_pause)) > . do_connection_and_query_stuff() > > It works for me. Just play with the pause parameters until it fails > and add a little. thanks, this worked for me too. slows down the program, but at least it works. :) -- Helge Aksdal -- http://mail.python.org/mailman/listinfo/python-list