Hello Monks,

I have a need for multiple producer processes to send small messages to a single consumer process all living on the same server - these do not have to be received in order or be guaranteed. Based on reading about socket domains and types, I decided to use AF_UNIX domain and datagram type.

Patching together what I could glean from perldoc and the perl cookbook, here is my code for server and client further below.

The problem is the server starts up and seems to wait at $sock->recv() as expected, but as soon as I run the client, the server comes out of the while loop without printing the data that was received and exits. I would have expected a server output of "Hello" and for the server to continue to listen. Also, nothing is printed for $@ or $! in either server or client

This has been driving me crazy for some hours now. Any help would be appreciated. Thanks!

Server:
#!/usr/bin/perl $| = 1; use strict; use IO::Socket::UNIX; my $SOCK_PATH = "/tmp/mysock"; unlink $SOCK_PATH; my $sock = IO::Socket::UNIX->new( Type => SOCK_DGRAM(), Local => $SOCK_PATH, Listen => 10, ) or die "error: $@"; my $data; while ($sock->recv($data, 1024)) { print "received: $data\n"; } print "exiting: $!\n";
Client
#!/usr/bin/perl $| = 1; use strict; use IO::Socket::UNIX; my $SOCK_PATH = "/tmp/mysock"; my $sock = IO::Socket::UNIX->new( Type => SOCK_DGRAM(), Peer => $SOCK_PATH, ); $sock->send("Hello") or die "error: $@";

In reply to Unix socket domain datagram within local server by evergreen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.