G'day.

I've been trying to develop an application using perl sockets; but
IO::Socket seems to be pretty dodgy in the way it handles some stuff (or its
just me - heh, probably the latter).

A heavily cut down version of the program is below (enough to replicate the
error, in any case).

server.pl:
--
#!/usr/bin/perl
use Net::hostent;
use IO::Socket::INET;
use IO::Select;

my $s = new IO::Select;

 $IP = '10.12.0.1';
 $PORT = 45005;

my $server = new IO::Socket::INET(LocalAddr     => $IP,
                                  LocalPort     => $PORT,
                                  Proto         => 'tcp',
                                  Listen        => SOMAXCONN,
                                  ReuseAddr     => 1);

 # Listen for multiple connections.
$s->add($server);
 print ">> $0 accepting connections on $PORT\n";

while (my @ready = $s->can_read())
{
    foreach my $fh (@ready)
    {
        if ($fh == $server)
        {
            my $new = $server->accept;
            $s->add($new);
            my $hostinfo = inet_ntoa($new->peeraddr);
             # Show IP that just connected.
            print "CONN >> $hostinfo\n";
        }
        else
        {
            my $in_ip = inet_ntoa($fh->peeraddr);
            my $in_text = scalar <$fh>;
             # If the client closes the connection, remove this socket, but
keep the script running, waiting/serving other connections.
            if ($in_text ne "") { } else { $s->remove($fh); $fh->close;
print "DISCONN >> $in_ip\n"; };
             # Every time "TEXT\n" is sent, display this
            print "$in_ip >> $in_text";
        }
    }
}

print "Program end.\n";
--

What its meant to do:  Listen on a port for connections, allow multiple
connections at once (hence the foreach() forking), and when the client
quits, successfully closes the connection.

It works...  Kinda.  I've written a client application in VB which connects
to this port - except, when the VB program quits, the perl script says this
and crashes:

Bad arg length for Socket::inet_ntoa, length is 0, should be 4

I'm completely stumped as to why.  I've done very little work with
IO::Socket before.

If I telnet to this port, type information, then quit, the server shows the
"disconnect" perfectly, and doesn't crash.  Its just certain programs that
connect to the port that make it bomb out (and I don't want the application
easily crashable).

Cheers if anybody can help (or point me to somewhere that can).  I don't
really care how it's done - with IO::Socket or not, just as long as I can
get something that does what the above script does.  (Without the error,
obviously).

- xfesty


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to