Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use AnyEvent;
- use ZeroMQ ':all';
- use constant MDP_CLIENT_PROTO => "MDPC02";
- use constant MDP_WORKER_PROTO => "MDPW02";
- use constant MDP_READY => "\x01";
- use constant MDP_REQUEST => "\x02";
- use constant MDP_PARTIAL => "\x03";
- use constant MDP_FINAL => "\x04";
- use constant MDP_HEARTBEAT => "\x05";
- use constant MDP_DISCONNECT => "\x06";
- my $service = "test_svc";
- my $ctx = ZeroMQ::Context->new();
- my $sock = $ctx->socket(ZMQ_DEALER);
- $sock->connect("tcp://localhost:5110");
- my $async = 1;
- my($cv, $w);
- if ($async)
- {
- my $fd = $sock->getsockopt(ZMQ_FD);
- print "set up wait on fd=$fd\n";
- $cv = AE::cv;
- $w = AE::io $fd, 0, sub { print "Read ready\n"; $cv->send() };
- }
- $sock->send(MDP_CLIENT_PROTO, ZMQ_SNDMORE);
- $sock->send(MDP_REQUEST, ZMQ_SNDMORE);
- $sock->send($service, ZMQ_SNDMORE);
- $sock->send("1", ZMQ_SNDMORE);
- $sock->send("hello world");
- if ($async)
- {
- $cv->recv;
- do_receive($sock);
- }
- else
- {
- do_receive($sock);
- }
- sub do_receive
- {
- my($sock) = @_;
- my $msg = $sock->recv();
- my $d = $msg->data;
- $d =~ s/([\x00-\x1f])/sprintf("0x%02x", ord($1))/ge;
- print "Rcv: $d\n";
- while ($sock->getsockopt(ZMQ_RCVMORE))
- {
- $msg = $sock->recv();
- my $d = $msg->data;
- $d =~ s/([\x00-\x1f])/sprintf("0x%02x", ord($1))/ge;
- print "Rcv: $d\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment