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

Discussion in 'Python' started by Jp Calderone, Jun 25, 2005.

  1. Jp Calderone

    Jp Calderone Guest

    On Fri, 24 Jun 2005 21:21:34 -0400, Peter Hansen <> wrote:
    >ncf wrote:
    >> Heh, like I said. I was not at all sure. :p
    >>
    >> 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
     
    Jp Calderone, Jun 25, 2005
    #1
    1. Advertisements

  2. On 2005-06-25, Jp Calderone <> 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?!!
     
    Grant Edwards, Jun 25, 2005
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian von Essen

    Listening socket not seen outside of localhost

    Christian von Essen, Jun 21, 2004, in forum: Python
    Replies:
    2
    Views:
    517
    Christian von Essen
    Jun 21, 2004
  2. pwilkins
    Replies:
    7
    Views:
    624
    Grant Edwards
    Jun 25, 2005
  3. Giovanni Tumiati
    Replies:
    2
    Views:
    412
    Grant Edwards
    Jun 25, 2005
  4. Jp Calderone
    Replies:
    2
    Views:
    463
    Grant Edwards
    Jun 25, 2005
  5. Spendius
    Replies:
    5
    Views:
    455
    Arne Vajhøj
    Oct 13, 2008
  6. Igor Katson
    Replies:
    11
    Views:
    22,257
    Lawrence D'Oliveiro
    May 31, 2009
  7. cerr

    listening socket

    cerr, Sep 8, 2010, in forum: Python
    Replies:
    3
    Views:
    753
    Grant Edwards
    Sep 8, 2010
  8. hisan
    Replies:
    1
    Views:
    2,319
    Dan Stromberg
    Jun 25, 2012
Loading...