The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::Async::ZMQ - IO::Async support for ZeroMQ

VERSION

version 0.002

SYNOPSIS

  use IO::Async::Loop;
  use Net::Async::ZMQ;
  use Net::Async::ZMQ::Socket;

  use ZMQ::LibZMQ3;  # or ZMQ::LibZMQ4
  use ZMQ::Constants qw(
    ZMQ_REQ
    ZMQ_NOBLOCK
    ZMQ_EVENTS ZMQ_POLLIN
  );

  my $loop = IO::Async::Loop->new;

  my $ctx = zmq_init();
  my $client_socket = zmq_socket( $ctx, ZMQ_REQ );
  zmq_connect( $client_socket, "tcp://127.0.0.1:9999" );

  my $counter = 0;

  my $zmq = Net::Async::ZMQ->new;

  zmq_sendmsg( $client_socket, "initial message" );

  $zmq->add_child(
    Net::Async::ZMQ::Socket->new(
      socket => $client_socket,
      on_read_ready => sub {
        while ( zmq_getsockopt( $client_socket, ZMQ_EVENTS ) & ZMQ_POLLIN ) {
          my $recvmsg = zmq_recvmsg( $client_socket, ZMQ_NOBLOCK );
          my $msg = zmq_msg_data($recvmsg);
          zmq_sendmsg( $client_socket, "hello @{[ $counter++ ]}" );
        }
      },
    )
  );

  $loop->add( $zmq );

  $loop->run;

DESCRIPTION

A subclass of IO::Async::Notifier that can hold ZMQ sockets that are provided by Net::Async::ZMQ::Socket.

Supports sockets from the following libraries:

EXTENDS

SEE ALSO

AUTHOR

Zakariyya Mughal <zmughal@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Zakariyya Mughal.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.