in reply to Mixing sysread() with <FILEHANDLE>?
To solve your binary data problem, how about implement a simple encoding scheme?
The point is that interaction with a network server is done via sending and receiving messages, and so it's natural to have subroutines or methods to perform those functions:sub write_binary { my $fh = shift; my $data = shift; print $fh unpack("H*", $data), "\n"; } sub read_binary { my $fh = shift; my $line = <$fh>; chomp; return pack("H*", $line); }
Encapsulating the interaction this way allows you to easily later change how the message sending is performed (use of syswrite or print, choice of encoding, etc.) Moreover, you'll need this encoding layer if you ever want to transmit anything more complex than a simple octet string. So if you want to send two data values, or an array of values or even Unicode code-points, you'll need an encoding layer.my $server = ...; $server->send_message("Hello"); ... $msg = $server->receive_message(); ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Mixing sysread() with <FILEHANDLE>?
by wanna_code_perl (Friar) on May 26, 2008 at 22:42 UTC |