in reply to Socket Differences between Win32/Darwin and *nix.

I haven't done very much socket programming, but I suspect that an issue is that on Unix, a bound socket is not immediately released when you quit. (I have certainly run into behaviour like this before.) Therefore there is a (possibly considerable) delay after successfully binding and then quitting before anything else can successfully bind to that port again.

Therefore I would suggest organizing your server in a more traditional way. Rather than returning out of your accept loop, plan to get into an accept loop and then stay there servicing more requests until your program is done.

  • Comment on Re (tilly) 1: Socket Differences between Win32/Darwin and *nix.

Replies are listed 'Best First'.
Re: Re (tilly) 1: Socket Differences between Win32/Darwin and *nix.
by clintp (Curate) on Jan 10, 2002 at 19:30 UTC
    Excellent articles on this delay after closing a socket on a bound port are linked from here.

    OP: Read the FAQ articles (some are linked in the follow-ups) and if you decide that you want to bind on the port again immediately, use setsockopt and monkey with the SO_REUSEADDR option.

      Or simply add Reuse=>1 to your IO::Socket::INET->new call.

      Update: ...which was already in the original code. Which makes me wonder how this particular error could happen...

              - tye (but my friends call me "Tye")