Created
November 23, 2012 07:58
-
-
Save chenryn/4134446 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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