By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,378 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Nov 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Nov 17, 11:32 pm, 7stud <bbxx789_0...@yahoo.comwrote:
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.

a better question is why you are not using higher level libraries,
such as twisted
Nov 19 '07 #2

P: n/a
On Nov 19, 4:45 pm, snd...@gmail.com wrote:
a better question is why you are not using higher level libraries,
such as twisted
I don't know about Mr. 7stud, but when I was doing a networking class,
the prof recommended that we use C++ to learn socket programming.
Students asked the obvious question, "Can we do it in Java?". So long
as you're using sockets and not some higher level libraries. Some
people were jumping with joy.

I did mine in Python.

-Justin
Nov 20 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.