473,382 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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
2 1585
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John P | last post by:
Hi, I know that some older Unix programs that compile with GCC use socket.h to connect to and execute other programs. However, I am using Visual C++ 6.0 and it doesn't seem to have socket.h...
7
by: Michi Henning | last post by:
Hi, I'm using a non-blocking connect to connect to a server. Works fine -- the server gets and accepts the connection. However, once the connection is established, I cannot retrieve either the...
3
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library....
6
by: Laxmikant Rashinkar | last post by:
Is there any way to use a C# socket in promiscuous mode? Any sample code that shows how this is done? any assistance is much appreciated! thanks LK
0
by: Stuart Norris | last post by:
Dear Group, I am having a problem setting SocketOptionName.SendTimeout on a client TCPIP application using the sockets in .NET. From the on-line help it is possible to set a...
3
by: Michael Maercker | last post by:
hi! i'm really not into networking at all and have now been asigned the task of porting a vb6-code into vb.net (compact framework, in this case) and the code uses the winsock-control. i quickly...
2
by: Stressed Out Developer | last post by:
We have an application that has a 200 count loop that does the following: ' Each time thru the loop we pass the next IP Address is a range (aka 192.168.4.50 thru 192.168.4.254) Try If...
6
by: 7stud | last post by:
My question pertains to this example: #!/usr/bin/env python import socket, sys, time host = sys.argv textport = sys.argv s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.