Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save horatio-sans-serif/416637 to your computer and use it in GitHub Desktop.
Save horatio-sans-serif/416637 to your computer and use it in GitHub Desktop.
AnyEvent::MessagePack -> node-msgpack
seems to work as expected... yay.
recv 4 bytes
147
1
2
3
unpacked 1,2,3
[ 1, 2, 3 ]
#!/tmp/node/bin/node
// ^^ built for node-msgpack support (see it's README)
sys = require('sys');
msgpack = require('msgpack');
net = require('net');
server = net.createServer(function (c) {
c.addListener('data', function (buf) {
sys.puts('recv ' + buf.length + ' bytes');
for (var i=0, n=buf.length; i<n; ++i)
sys.puts(buf[i]);
var obj = msgpack.unpack(buf);
sys.puts("unpacked " + obj);
sys.puts(sys.inspect(obj));
});
});
server.listen(8080);
#!/usr/bin/env perl
use AnyEvent::MessagePack;
use AnyEvent::Handle;
use AnyEvent::Socket;
my $cv = AnyEvent->condvar;
tcp_connect localhost => 8080, sub {
my $fh = shift or die "failed to connect: $!";
print "Connected!\n";
my $handle;
$handle = new AnyEvent::Handle
fh => $fh,
on_error => sub {
warn "error $_[2]\n";
$_[0]->destroy;
},
on_eof => sub {
$handle->destroy;
warn "done.\n";
};
$handle->push_write(msgpack => [1,2,3]);
};
$cv->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment