Created
December 25, 2014 02:27
-
-
Save wxg4net/b54d3caf3fa034341dc5 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 IO::Socket::UNIX; | |
use JSON; | |
use AnyEvent; | |
use AnyEvent::Handle; | |
use Data::Dumper; | |
my $socket_path='/tmp/ddd.sock'; | |
unlink $socket_path if -e $socket_path; | |
my $socket = IO::Socket::UNIX->new( | |
Type => SOCK_STREAM, | |
Local => $socket_path, | |
Listen => 1, | |
); | |
die "Can't create socket: $!" unless $socket; | |
$client = $socket->accept; | |
my %auth = ('type'=>'auth', 'user'=>'sss', 'passwd'=>'ssssssss'); | |
my $data = encode_json \%auth; | |
print "\n"; | |
print $client $data; | |
my $handle; | |
$handle = new AnyEvent::Handle | |
fh => $client, | |
on_error => sub { | |
AE::log error => $_[2]; | |
$_[0]->destroy; | |
$handle->destroy; | |
}, | |
on_eof => sub { | |
$handle->destroy; | |
AE::log info => "Done."; | |
}; | |
$handle->push_read (json => sub { | |
my $arr = $_[1]; | |
print Dumper $arr; | |
print "\n"; | |
}); | |
$cv = AE::cv; | |
$cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment