Skip to content

Instantly share code, notes, and snippets.

@chenryn
Created November 23, 2012 07:58
Show Gist options
  • Save chenryn/4134446 to your computer and use it in GitHub Desktop.
Save chenryn/4134446 to your computer and use it in GitHub Desktop.
use AnyEvent;
use AnyEvent::PocketIO::Client;
use Data::Dumper;
use warnings;
use strict;
my $client = AnyEvent::PocketIO::Client->new;
my $channel = '3:::{"type":"subscribe","channel":"syslog"}';
my $server = '192.168.1.199';
my $port = '8080';
$client->on('open' => sub {
print Dumper @_;
});
$client->on('connect' => sub {
print STDERR "get connect : $_[1]\n";
});
$client->on('disconnect' => sub {
print STDERR "get disconnect : $_[1]\n";
});
$client->on('heartbeat' => sub {
print STDERR "get heartbeat : $_[1]\n";
});
$client->on('message' => sub {
print STDERR "get message : $_[1]\n";
});
my $cv = AnyEvent->condvar;
$client->handshake( $server, $port, sub {
my ( $error, $self, $sesid, $hb_timeout, $con_timeout, $trans ) = @_;
$client->open( 'websocket' => sub {
$client->send("$channel");
$self->reg_event('message' => sub {
print @_;
});
} );
} );
$cv->wait;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment