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

7

7stud

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.
 
S

sndive

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
 
J

Justin Kwok

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
 
D

Dennis Lee Bieber

I did mine in Python.
Heh... Sounds like my data structures/algorithms class...
Assignment: Hashed-head, multiple-linked list (a name/phone number
scheme).

Professor permitted any language he could understand (no APL or
SNOBOL; FORTRAN, COBOL, Assembly [Xerox Sigma-6], BASIC)...

So... I chose BASIC; even though the mainframe's BASIC only allowed
a mere FOUR open data files... I ended up with a user-interface main
program, and three utility programs that I "chain-linked" [overlayed] as
needed.

{and two years later, to finalize my needed credit count, I took "INTRO
to BASIC" <G>}

Of course, how many students these days have even had to code an
HHMLL...
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top