sockets: why doesn't my connect() block?

7stud bbxx789_05ss at yahoo.com
Sun Nov 18 00:32:50 EST 2007


According to "Python in a Nutshell(2nd)", p. 523:

connect:   s.connect((host, port))
...
Blocks until the server accepts or rejects the connection attempt.

However, my client program ends immediately after the call to
connect()--even though my server program does not call accept():


#server----------------
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = 3200
s.bind( ('', port) )
s.listen(5)

import time
time.sleep(20)



#client----------------
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = 'localhost'
port = 3200

s.connect( (host, port) )
print 'done'


If I start my server program and then start my client program, the
client ends immediately and displays: done.  I expected the client
program to block indefinitely.



More information about the Python-list mailing list