3 # Contributed by Bastiaan Bakker for SOCKETMAP
4 # $Id: socketmapClient.pl,v 1.1 2003-05-21 15:36:33 ca Exp $
9 die "usage: $0 <connection> <mapname> <key> [<key2> ...]" if (@ARGV < 3);
11 my $connection = shift @ARGV;
12 my $mapname = shift @ARGV;
16 if ($connection =~ /tcp:(.+):([0-9]*)/) {
17 $sock = new IO::Socket::INET (
22 } elsif ($connection =~ /((unix)|(local)):(.+)/) {
23 $sock = new IO::Socket::UNIX (
28 die "unrecognized connection specification $connection";
31 die "Could not create socket: $!\n" unless $sock;
33 while(my $key = shift @ARGV) {
34 my $request = "$mapname $key";
35 netstringWrite($sock, $request);
37 my $response = netstringRead($sock);
39 print "$key => $response\n";
48 print $sock length($data).':'.$data.',';
53 my $saveSeparator = $/;
55 my $dataLength = <$sock>;
56 die "cannot read netstring length" unless defined($dataLength);
59 if ($sock->read($data, $dataLength) == $dataLength) {
60 ($sock->getc() eq ',') or die "data misses closing ,";
62 die "received only ".length($data)." of $dataLength bytes";