use strict; use IO::Socket::SSL; use ZMQ::FFI; use ZMQ::FFI::Constants qw (ZMQ_SUB); use AnyEvent; use EV; my $wsport = '3000'; my $zmqhost = 'tcp://localhost:5555'; my $subject = 'event'; Net::WebSocket::Server->new( listen => $wsport; on_connect => sub { my ($serv, $conn) = @_; $conn->on( ready => sub { my $context = ZMQ::FFI->new(); my $subsocket = $context->socket(ZMQ_SUB); $subsocket->connect($zmqhost); $subsocket->subscribe($subject); my $fd = $subsocket->get_fd(); my $w = AE::io $fd, 0, sub { while ($subsocket->has_pollin) { $conn->send_utf8($subsocket->recv()); } }; EV::run(); }, ); }, )->start;