I wrote a simple script to see how I can use UNIX domain socket to implement a client/server pair

The script can be ran as client/server.

The client side does a push_write, the server does push_read.
Unfortunately the whole thing doesn't seem to work, both server and client simply sit there with no output.
Please advise, any pointers will be greatly appreciated. I am sure I missed something trivial.
I start the server first (SCRIPT) and the client next (SCRIPT 1).

#!/usr/bin/perl use v5.10; use strict; use warnings; use AnyEvent::Socket; use AnyEvent::Handle; my $client = shift; # undef - server, or client my $path = "/tmp/socket"; my %data = (a => b => c => d =>); my $cv = AnyEvent->condvar; # Will send when client breaks connectio +n if ($client) { # Client tcp_connect( "unix/", $path, sub { if (!@_) { # Error print STDERR "Failed connect to $path:$!\n"; $cv->end; return; } print "Client connected to $path\n"; my ($fh) = shift; #Create a handle and save it my $hdl; $hdl = AnyEvent::Handle->new( fh => $fh, on_error => sub { my ($hdl, $fatal, $msg) = @_; AE::log error => $msg; $hdl->destroy; $cv->send; }, on_eof => sub { my ($hdl1, $fatal, $msg) = @_; $hdl1->destroy; # destroy handle AE::log info => "Done."; $cv->send; } ); # Write to the server $hdl->push_write (storable => \%data); 1; }, ) } else { # Server print "Server\n"; tcp_server( "unix/", $path, sub { # Accept callback and start rolling my ($fh, $host, $port) = @_; print "ACCEPTED:host=$host\n"; my $hdl = AnyEvent::Handle->new( fh => $fh, on_error => sub { my ($hdl1, $fatal, $msg) = @_; AE::log error => $msg; $hdl1->destroy; $cv->send; }, on_eof => sub { my ($hdl1) = @_; $hdl1->destroy; # destroy handle AE::log info => "Done."; } ); # Read from the client $hdl->push_read (storable => sub { my ($hdl1, $data) = @_; print "Read @{[ref($data)]}\n"; }); 1; }, ); print "Listening on $path\n"; } $cv->recv;

In reply to AnyEvent server/client don't cooperate by yuri123

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.