Hi!
I'm new with perl, so please have patience if I misunderstood anything, or got something wrong.
What I'm trying to do is connect to a websocket, read the data the ws is sending and do some stuff with it.
My code is connecting to the ws but when I try to read and print in the console the data readed it shows nothing.
Can you guys help me?
here's my code:
#!/usr/bin/env perl
use strict;
use warnings;
use lib 'lib';
use Data::Dumper;
use AnyEvent;
use AnyEvent::Socket;
use AnyEvent::Handle;
$|++;
my $cv = AnyEvent->condvar;
my $ws_handle;
$ws_handle = AnyEvent::Handle->new(
connect => [ 'localhost', '8082' ],
keepalive => 1,
on_eof => sub {
print ("! Server disconnected");
},
on_read => sub {
my ($handle) = @_;
my $buf = delete $handle->{rbuf};
print "teste";
},
on_connect => sub {
my ($handle, $host, $port, $retry) = @_;
print "Server connected\n"; # this works
},
on_connect_error => sub {
my ($handle, $message) = @_;
print $message;
},
);
$cv->recv;