Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Newbie question: how to keep a socket listening?

Reply
Thread Tools

Re: Newbie question: how to keep a socket listening?

 
 
Jp Calderone
Guest
Posts: n/a
 
      06-25-2005
On Fri, 24 Jun 2005 21:21:34 -0400, Peter Hansen <(E-Mail Removed)> wrote:
>ncf wrote:
>> Heh, like I said. I was not at all sure.
>>
>> Nevertheless, could this be the problem? =\

>
>You *may* correct, mainly because the OP's code doesn't appear to spawn
>off new threads to handle the client connections, which means he can
>handle only one connection at a time. Specifically, while he is talking
>to one client he is not also in an accept() call on the server socket,
>which means there will be (because of the listen(1) call) only a single
>pending connection allowed in the backlog.
>
>I haven't attempted a thorough analysis... just this much, trying to see
>whether it is obvious that the listen(1) is at fault -- and it's not
>obvious. I thought this response might clarify the meaning of listen(1)
>a little bit for some folks nevertheless.


The argument to listen() is only a _hint_ to the TCP/IP stack. Linux, at least, will not create a buffer large enough for only a single connection. You can test this easily: create a socket, bind it to an address, call listen(1) on it, and *don't* call accept(). Telnet (or connect somehow) repeatedly, until your connection is not accepted. On my system (Linux 2.6.10), I can connect successfully 8 times before the behavior changes.

Jp
 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      06-25-2005
On 2005-06-25, Jp Calderone <(E-Mail Removed)> wrote:

> The argument to listen() is only a _hint_ to the TCP/IP stack.
> Linux, at least, will not create a buffer large enough for
> only a single connection. You can test this easily: create a
> socket, bind it to an address, call listen(1) on it, and
> *don't* call accept(). Telnet (or connect somehow)
> repeatedly, until your connection is not accepted. On my
> system (Linux 2.6.10), I can connect successfully 8 times
> before the behavior changes.


I had noticed that once upon a time. I had forgotten that 8
was the minimum, but I do remember that 1 didn't result in a
second connect failing.

--
Grant Edwards grante Yow! Ha ha Ha ha Ha ha
at Ha Ha Ha Ha -- When will I
visi.com EVER stop HAVING FUN?!!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How keep python socket alive for ever by setting Keep alive flag. hisan Python 1 06-25-2012 05:30 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments