perlofwisdom has asked for the wisdom of the Perl Monks concerning the following question:
When I run it the code, I get the following response:#!/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);
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.Receiver... Could not create socket: Bad file number
I have reduced the code to essentially a null file (shebang line only):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
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:#!/usr/bin/perl -w
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.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)
|
|---|