evergreen has asked for the wisdom of the Perl Monks concerning the following question:
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:Client#!/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";
#!/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: $@";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unix socket domain datagram within local server
by haukex (Archbishop) on Dec 22, 2018 at 07:53 UTC | |
by evergreen (Novice) on Dec 22, 2018 at 19:48 UTC | |
|
Re: Unix socket domain datagram within local server
by tybalt89 (Monsignor) on Dec 22, 2018 at 07:57 UTC |