in reply to Could not create socket: Bad file number

This minor modification of your code worked. I set the server to 'localhost' and used a number rather than a string for the port number.

#!/usr/bin/perl -w use IO::Socket; print "Receiver...\n"; my $sock = new IO::Socket::INET ( LocalHost => 'localhost', 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);
The results were:

C:\Code>perl socket.pl Receiver... Testing This is a test by telnetting to port 7070 C:\Code>

Replies are listed 'Best First'.
Re^2: Could not create socket: Bad file number
by ikegami (Patriarch) on Aug 30, 2007 at 21:13 UTC
    Actually, the LocalHost line should be removed entirely unless there is a desire to bind to a particular interface (which is very rare). That shouldn't cause that problem, though.
      Exactly. Just to emphasize; you (usally) only need the LocalHost argument if you have multiple network connectors on your machine and you only want to listen on one of them.

      If you *do* need to do this, it may be easier to specify the IP address instead of the host name, since that may be easier than configuring the right hostname(s) to the right port(s)

        I removed the LocalHost argument -- no change. Are there Unix settings that need to be in place for Socket communications to work properly? i.e. maybe that port is blocked?
Re^2: Could not create socket: Bad file number
by perlofwisdom (Pilgrim) on Aug 30, 2007 at 21:08 UTC
    Thanks for the excellent suggestions, but no luck yet. I checked "netstat -a | grep 7070" and got no results. I tried using 7070 instead of '7070' -- no change. I switched the real name of the host with 'myhost' just in case my company has some privacy rule I'm not aware of. The actual code does in fact use the actual name of the server. I'm still trying to figure out what YMMY stands for, :).
      If port 7070 is defined in the /etc/services file on your host, you will need to use "netstat -an | grep 7070" to match or use telnet to check with the command "telnet localhost 7070". It should not make a connection. Locally port 7070 is used for arcp (don't know what that is) but there is an entry in /etc/services for port 7070.