Skip to content

Instantly share code, notes, and snippets.

@dbcm
Created October 6, 2014 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbcm/f6068983b6fbf96111da to your computer and use it in GitHub Desktop.
Save dbcm/f6068983b6fbf96111da to your computer and use it in GitHub Desktop.
Resource temporarily unavailable
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