Created
May 28, 2010 01:57
-
-
Save horatio-sans-serif/416637 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
AnyEvent::MessagePack -> node-msgpack | |
seems to work as expected... yay. | |
recv 4 bytes | |
147 | |
1 | |
2 | |
3 | |
unpacked 1,2,3 | |
[ 1, 2, 3 ] |
This file contains hidden or 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
#!/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); |
This file contains hidden or 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
#!/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