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

Hi all,

I've been having some issues creating a UNIX domain server using the IO::Socket::UNIX package.

This piece of code works fine,

my $NAME = '/tmp/catsock';
my $uaddr = sockaddr_un($NAME);
my $proto = getprotobyname('tcp');

socket(Server,PF_UNIX,SOCK_STREAM,0) || die "socket: $!";
unlink($NAME);
bind (Server, $uaddr) || die "bind: $!";
listen(Server,SOMAXCONN) || die "listen: $!";


But when I try and use the OO interface into the sockets such as this,

unlink("/tmp/catsock");
$server = IO::Socket::UNIX->new(LocalAddr => "/tmp/catsock",
Type => SOCK_STREAM,
Listen => 5)
or die "Can't make the server socket: $@\n";

It never succeeds?
Can anyone provide some enlightenment??

TIA,
Ben Timms

Replies are listed 'Best First'.
Re: Perl UNIX sockets dilemma
by tadman (Prior) on Feb 03, 2001 at 00:48 UTC
    You've got the right idea, but you're looking for the errors in the wrong place. $@ is for eval errors, not run-time errors. Those are reported in $!, or $ERRNO if you're using English.

    If you fix that, $! is "Invalid argument". I presume that is attributable to the "Listen => 5" parameter, because when that's removed, it works fine.

    The "Listen" parameter is to define how many pending connections you want to have, but if your process is attentive enough and accepts them as soon as connections are initiated, the default value should be fine (which is, I believe, 5 anyway).
Re: Perl UNIX sockets dilemma
by Anonymous Monk on Feb 02, 2001 at 19:56 UTC
    Duh. Me stupid.... it's not LocalAddr - it's Local.

    Sorry for wasting your bandwidth.
    Ben