Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use')

Discussion in 'Python' started by Steve Holden, Feb 1, 2009.

  1. Steve Holden

    Steve Holden Guest

    Laszlo Nagy wrote:
    >
    >> 8<------------------------------
    >>
    >>
    >>> ....... Setting the
    >>> SO_REUSEADDR flag on POSIX fixes this problem (don't set it on Windows,
    >>> though).
    >>>

    >>
    >> Why not? I have been merrily setting it, and I have not noticed
    >> anything weird.
    >> (yet)
    >>

    > Please see my original post. I specifically stated that I do not want to
    > use setsockopt and be able to listen on the same port from many
    > processes. I knew that I could use SO_REUSEADDR, but I'm heistating to
    > do so. I must guarantee that only one process listens on a given port at
    > the same time.


    My previous reply assumed you are running some UNIX-like operating
    system. If you are on Windows then Jean-Paul's advice stands, as Windows
    *does* allow several processes to listen on the same port and randomly
    delivers incoming connections to one of the listening processes.

    I believe this is because Microsoft failed to understand the original
    meaning of SO_REUSEADDR for their early TCP implementations, and
    persisted with this ghastly error in the name of backwards
    compatibility, justifying it by suggesting that listener pools could be
    created. Or some such nonsense. Perhaps someone with more insight into
    the development process could comment. It seems to me it's completely
    bizarre.

    However, under Windows 2000 and later you should find there's an
    SO_EXCLUSIVEADDRUSE flag which you can use to ensure a single listener -
    see http://msdn.microsoft.com/en-us/library/ms740621(VS.85).aspx. No
    need for separate locks.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
     
    Steve Holden, Feb 1, 2009
    #1
    1. Advertising

  2. Steve Holden

    Aahz Guest

    Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Address already in use')

    In article <>,
    Grant Edwards <> wrote:
    >On 2009-02-01, Steve Holden <> wrote:
    >
    >> I believe this is because Microsoft failed to understand the
    >> original meaning of ___________________, and persisted with
    >> this ghastly error in the name of backwards compatibility,
    >> justifying it by suggesting that _________________________.

    >
    >Somebody should have cards printed up...


    +1 QOTW
    --
    Aahz () <*> http://www.pythoncraft.com/

    Weinberg's Second Law: If builders built buildings the way programmers wrote
    programs, then the first woodpecker that came along would destroy civilization.
     
    Aahz, Feb 3, 2009
    #2
    1. Advertising

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. Laszlo Nagy
    Replies:
    1
    Views:
    5,083
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    1,026
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    594
    Laszlo Nagy
    Feb 1, 2009
  4. Steve Holden
    Replies:
    0
    Views:
    711
    Steve Holden
    Feb 1, 2009
  5. Hendrik van Rooyen
    Replies:
    0
    Views:
    593
    Hendrik van Rooyen
    Feb 2, 2009
Loading...

Share This Page