Operating System - HP-UX
1821980 Members
3596 Online
109638 Solutions
New Discussion юеВ

Perl IPC UNIX-Domain Sockets

 
Russ Jones_1
Advisor

Perl IPC UNIX-Domain Sockets

I'm trying to write a client/server pair of Perl scripts that will communicate with TCP protocol over UNIX-Domain Sockets.

I'm using Perl 5.6, HPUX 11.11, and the IO::Socket module that comes standard with Perl 5.6.

I'm attaching a short little test script that shows what I'm doing, but the real guts of it is:

$server = IO::Socket::UNIX->new(
LocalAddr => '/tmp/mysock',
Type => SOCK_DGRAM,
Listen => 5)
or die $!;


This executes with no errors, but the /tmp/mysock file doesn't get created, and then when I do the $client = $server->accept() it doesn't block waiting for input. It just falls through.

I've been through the O'Reilly Perl books for two days now, and I can't seem to spot my error. And I KNOW the people here aren't nearly as mean as on comp.lang.perl.misc, so here I am.

Anyone have any insight?

Thanks
Russ
4 REPLIES 4
Steve Steel
Honored Contributor

Re: Perl IPC UNIX-Domain Sockets

Hi


Try data in

http://www.perlfect.com/articles/sockets.shtml

http://www.linuxchix.org/pipermail/techtalk/2001-August/008554.html


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Russ Jones_1
Advisor

Re: Perl IPC UNIX-Domain Sockets

Thanks, Steve, but those links didn't help. The first was about INET sockets, which I have no problem with, and the other was all stuff that I've already tried, using both the Socket module, and the equivalent calls in IO::Socket.
Steven Gillard_2
Honored Contributor

Re: Perl IPC UNIX-Domain Sockets

The LocalAddr argument is not valid for UNIX domain sockets, it should be 'Local' instead:

$server = IO::Socket::UNIX->new(
Local => '/tmp/mysock',
Type => SOCK_DGRAM,
Listen => 5)
or die $!;

That should work fine.

If you print $! after the failed accept() called you'd see an "invalid argument" error.

Cheers,
Steve

Russ Jones_1
Advisor

Re: Perl IPC UNIX-Domain Sockets

Christiansen's Cookbook typos bit me again! It actually wants to be:

our $server = IO::Socket::UNIX->new(
Local => '/tmp/mysock',
Type => SOCK_STREAM,
Listen => 5,
proto => 0) or die '$@';

The real parm is 'Local=>' and according to the socket(2) manpage, datagram sockets aren't supported for Unix domain sockets, and from what I can tell, datagram sockets probably aren't reliable enough for my purposes anyway.

And with IO::Socket you have to check $@ instead of $!.

Whew.

Anyway, thanks for your help!

Russ