Socket connection

sik0fewl xxdigitalhellxx at hotmail.com
Thu Mar 6 16:32:15 EST 2003


Hi,

I'm having some problems with some socket/thread code.

What I'm doing is starting another thread to do the actual connect() so 
that my process doesn't block while connect does socket.getaddrinfo().

What I have works fine if the host is localhost, otherwise it doesn't 
seem to ever connect.

Here's the basis of my code:

-----

def threaded_connect(sock, address, port = None):
     try:
         sock.connect((address, port))
     except:
         pass

x = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
x.setblocking(0)

thread.start_new_thread(threaded_connect, (x, 'www.hotmail.com', 80))

while 1:
	# then I do select that waits for x to become writable
	# (ie, connected)

-----

Like I said, the select() works fine when connecting to localhost, but 
when I try any other address (like www.hotmail.com) the select keeps 
timing out and x never becomes connected.

Any thoughts? Also, if there's a better way to do this, I'd like to know 
about it, too :) Although, I'd still like to know why this isn't working 
the way I expect.

--
Thanks in advance,
Ryan





More information about the Python-list mailing list