Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem. My script creates listening sockets using IO::Socket::INET, this way:
$!=$^E = ''; my $sk = IO::Socket::INET->new(Proto => "tcp", LocalPort => 9000, LocalAddr => "127.0.0.1", Listen => 5, Reuse => 1); print "unable to create socket: $! : $^E\n" if (!$sk);
(First it of course tries to connect to that port to see whether something is listening on it - if nothing does - it then tries to create listening socket using method above). For one of the script's users it fails on both his PC and laptop, both running WinXP Prof SP2. He said he checked 100 times that no firewall and antivirus sw is enabled (he has Norton AntiVirus and ZoneAlarm - but he pretends that he disabled them for testing). Does anybody knows what can be wrong with Perl or with his box? May be protocol number for "tcp" became unknown to Windows? The code above NEVER was able to created a socket for him on any of his computers. It successfully worked on all computers I can find around (including with Windows). He is using Perl 5.8.3 build 809 downloaded from activestate's site. On his box, some windows C/C++ programs that do the same (i.e. open sockets) work just fine. Because I have to email him a testcase and get a debug log from him, I can't debug the code comfortably.. The code prints the following for him: "unable to create socket: Unknown error : The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for". Did anybody ever see something like this?

Thank you very much for any suggestion and insight you may provide!

Replies are listed 'Best First'.
Re: IO::Socket::INET fails in rare cases on Windows (0+$!)
by tye (Sage) on Jan 30, 2005 at 18:09 UTC

    For socket errors on Win32 Perl, you want 0+$! not just $! (which will always be "unknown error", which is useless).

    - tye        

Re: IO::Socket::INET fails in rare cases on Windows
by BrowserUk (Patriarch) on Jan 30, 2005 at 17:49 UTC

    A google for that error suggests that the cause is: "The DNS is not properly configured on the workstation or there are problems with the DNS server".

    Whether that will help him track down his problem I don't know, but it tends to strongly indicate that it is a problem local to his configuration or network rather than anything that you can fix in the script.

    It's also hard to see how the snippet you posted would be causing a DNS lookup? How sure are you that it is that part of the code that is failing?


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
      Thank you for your answer!! I'm sure that this is the fragment that is failing because in my code "die" is used instead of "print" and script dies at that line.. It's possible that IO::Socket::INET tries to resolve string "127.0.0.1" or does some other (unnecessary!) query of DNS, probably I'll try to break DNS on my box to reproduce it and try to debug the IO::Socket::INET code to see what it does.. Thanks again!