1 #!/usr/local/bin/perl -w
12 my $host = 'localhost' ;
14 my $port = shift || 8888 ;
16 my $sock = IO::Socket::INET->new( "$host:$port" ) ;
17 $sock or die "can't connect to $host:$port\n" ;
19 #my $packet = Stem::Packet->new( codec => 'YAML' ) ;
20 my $packet = Stem::Packet->new() ;
22 print "type 'help' for help\n\n" ;
28 chomp( my $line = <> ) ;
29 next unless $line =~ /\S/ ;
31 #my $line = "foo bar bazz" ;
34 @data{ qw( op key value ) } = split( ' ', $line, 3 ) ;
36 my $write_buf = $packet->to_packet( \%data) ;
37 #print "WRITE [$$write_buf]\n" ;
39 syswrite( $sock, "${$write_buf}" ) ;
41 # this should be a proper non-blocking read loop but it is fine for this
44 my $bytes_read = sysread( $sock, my $read_buf, 8192 ) ;
45 last unless defined $bytes_read and $bytes_read > 0 ;
47 my $result = $packet->to_data( \$read_buf ) ;
49 # print "RESULT [$$result]\n" ;
50 print Dumper $result ;