I am having a spot of trouble getting socket communications to work on a Solaris 5.9 system. I don't think the code is actually the problem, since I can get it to work on other servers. Any help would be greatly appreciated. I have boiled the code down for simplicity's sake:
#!/usr/bin/perl -w use IO::Socket; print "Receiver...\n"; my $sock = new IO::Socket::INET ( LocalHost => 'myhost', LocalPort => '7070', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; my $new_sock = $sock->accept(); while(<$new_sock>) { print $_; } close($sock);
When I run it the code, I get the following response:
Receiver... Could not create socket: Bad file number
Are there Unix settings that need to be in place for Socket communications to work properly (i.e. could that port be blocked)? Several comments have revolved around the port (7070). As you can see from the listing below, 7070 is not in /etc/services, and netstat does not show any activity on port 7070.
smeau407:db1010:/export/home/oracle> -> grep 7070 /etc/services smeau407:db1010:/export/home/oracle> -> netstat -an | grep 7070 smeau407:db1010:/export/home/oracle> -> telnet localhost 7070 Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused
I have reduced the code to essentially a null file (shebang line only):
#!/usr/bin/perl -w
Then ran a truss on it. Two interesting things appeared, which I do not understand well enough to explain. So, with your kind permission, I include excerpts from the results of truss, and ask for expert opinion:
truss ./mtb_receive.pl execve("/usr/perl5/5.6.1/bin/perl", 0xFFBFFA94, 0xFFBFFAA4) argc = 3 resolvepath("/usr/lib/ld.so.1", "/usr/lib/ld.so.1", 1023) = 16 resolvepath("/usr/perl5/5.6.1/bin/perl", "/usr/perl5/5.6.1/bin/perl", +1023) = 25 stat("/usr/perl5/5.6.1/bin/perl", 0xFFBFF868) = 0 open("/var/ld/ld.config", O_RDONLY) Err#2 ENOENT stat("/usr/perl5/5.6.1/lib/sun4-solaris-64int/CORE/libperl.so.1", 0xFF +BFF370) = 0 resolvepath("/usr/perl5/5.6.1/lib/sun4-solaris-64int/CORE/libperl.so.1 +", "/usr/perl5/5.6.1/lib/sun4-solaris-64int/CORE/libperl.so.1", 1023) + = 57 : : fstat64(3, 0xFFBFED40) = 0 ioctl(3, TCGETA, 0xFFBFEE24) Err#25 ENOTTY read(3, " # ! / u s r / b i n / p".., 8192) = 1358 read(3, 0x0002E64C, 8192) = 0 llseek(3, 0, SEEK_CUR) = 1358 close(3) = 0 _exit(0)
One of our programmers discovered that LDAP may not be set up properly on this server. Notice the error from the open (Err#2 ENOENT), and the error from ioctl (Err#25 ENOTTY). The file from the open command (/var/ld/ld.config) does not exist. Could that be contributing to problems with sockets? UPDATE (8/31/2007): It turns out that LDAP was the culprit! The SA stopped the LDAP client, and voila! The original script started working like a champ. Thanks to all for your very helpful suggestions. As usual, your knowledge and willingness to share have helped me explore areas that I hadn't been exposed to previously -- I have learned a lot.

In reply to Could not create socket: Bad file number by perlofwisdom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.