Perhaps people can help me with this code... it's much simpler than previous but I am unable to get ip, port and won't send message or close socket... seems like does nothing... maybe I am not saving socket correctly or not referencing correctly.

use EV; use Asterisk::AMI; use Data::Dumper; use Net::WebSocket::EV; use HTTP::Server::EV; use Digest::SHA1 qw(sha1_base64); use threads; use threads::shared; use strict; $|++; my ($rsv,$opcode,$msg, $status_code); our @users : shared; my @users =(); my $cgi ; my $astman = Asterisk::AMI->new(PeerAddr => '127.0.0.1', PeerPort => '5038', Username => 'admin', Secret => 'emel1t0', Events => 'on', Handlers => { default => \&eventhandler } ); die "Unable to connect to asterisk" unless ($astman); sub eventhandler { my ($ami, $event) = @_; if($event->{'Event'} eq "Dial"){ if($event->{'SubEvent'} eq "Begin"){ &buscar_exten($event->{'ConnectedLineName'}); } if($event->{'SubEvent'} eq "End"){ &buscar_exten($event->{'ConnectedLineName'}); } } } HTTP::Server::EV->new->listen(50080, sub { $cgi = $_[0]; $cgi->header({ STATUS => '101 Switching Protocols', Upgrade => "websocket", Connection => "Upgrade", "Sec-WebSocket-Accept" => scalar sha1_base64( $cgi->{headers}{"Sec-WebSocket-Key"} . "2 +58EAFA5-E914-47DA-95CA-C5AB0DC85B11" ).'=', }); $cgi->{self} = $cgi; $cgi->{buffer}->flush_wait(sub { $cgi->{websocket} = Net::WebSocket::EV::Server->new({ fh => $cgi->{buffer}->give_up_handle, on_msg_recv => sub { ($rsv,$opcode,$msg,$status_code) = @_; my @dlogin=split(":",$msg); if(@dlogin[1] eq ""){ print "no autenticado\n"; } else{ push (@users, $cgi->{websocket}) +; } }, on_close => sub { my($code) = @_; $cgi->{self} = undef; $cgi = undef; }, buffering => 1, }); }); }, { threading => 0 }); sub buscar_exten{ my $exten=@_[0]; my $href; my $role; my $some; print "buscando si <$exten> esta logueada-\n"; foreach my $fn (@users) { open my $fh, ">&=$fn" ;# or warn $! and die; send($fh,"evento llamada $exten\n",0) ; print "}\n"; } } EV::loop;

In reply to Re^2: Perl an array of sockets by suhijo
in thread Perl an array of sockets by suhijo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.