is encoded like this - notice the byte 7 with value 0xc == 11, for 10+1 character in the response:For example, the response OFST -0.75
I started small and simple, from a code example similar to Camel 3 chapter 16 and got it basically working.810100000000000c4f465354202d302e3037350a
Question: can I configure IO:Socket::INET to receive data as binary and not stop receiving when it sees 0xa in the stream? How?VDIV 0.05 810100000000000
#!perl -w use strict; use IO::Socket; my $verbose = 1; print "===\n"; my $host = "127.0.0.1"; # or whatever my $port = 1861; my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => $port) or die "Couldn't connect to $host:$port\n$!\n$@\n"; my $msg = 'ofst?'; # send query $remote->send(wrap($msg)) or die "Couldn't send: $!\n$@\n"; # read the remote answer my $answer = <$remote> || '---'; print "answer: =$answer=\n"; my $response = unwrap($answer); print "response: =$response=\n"; close $remote; exit; sub wrap { my ($data) = @_; my $header = pack "C4N", hex '0x81', hex '0x1', 0, 0, length($data +); return $header . $data; } sub unwrap { my ($packet) = @_; my ($op, $hvers, $count, $data); ($op, $hvers, undef, undef, $count, $data) = unpack "C4NA*", $pack +et; { my $warn = ''; my $length = length($packet); if ($count != $length) { $warn .= "warn: $count != $length: \n"; } $warn .= unpack "H*", $packet; print STDERR "$warn\n" if $verbose; } return $data; } __END__
Edited by footpad, 23 June 2001 - 20:46 (PDT)
In reply to IO:Socket::INET - how to receive binary data by Rudif
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |