Created
October 6, 2014 21:28
-
-
Save dbcm/f6068983b6fbf96111da to your computer and use it in GitHub Desktop.
Resource temporarily unavailable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use 5.10.0; | |
use Data::Dumper; | |
use File::Temp; | |
use ZMQ::LibZMQ3; | |
use ZMQ::Constants qw(ZMQ_REQ); | |
my $server = shift; | |
my $path = File::Temp->new( UNLINK => 0 ); | |
my $context = zmq_init(); | |
if ( !$context ) { | |
die "zmq_init() failed with $!"; | |
} | |
say "Connecting to hello world server $path"; | |
my $requester = zmq_socket( $context, ZMQ_REQ ); | |
if ( !$requester ) { | |
die "zmq_socket() failed with $!"; | |
} | |
my $rv = zmq_connect( $requester, "ipc://$path" ); | |
if ( !$rv ) { | |
die "zmq_connect() failed with $!"; | |
} | |
if ($server) { | |
while (1) { | |
my $msg = zmq_recvmsg($requester); | |
if ( !$msg ) { | |
sleep 1; | |
next; | |
} | |
say Dumper($msg); | |
} | |
} else { | |
say "Sending request "; | |
zmq_sendmsg( $requester, zmq_msg_init_data('Hello') ); | |
say "Sent!"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment