Since it's using readInt, I'm assuming the int gets passed back in plain text with a newline to end it.
No. ReadInt() reads binary data, not ASCIIfied. See
ReadInt().
The (roughly) equivalent code in Perl would be:
if( $more ) {
syswrite( OUT, 1, chr( 64 ) );
$more = 0;
}
sysread( IN, 4, my $buf );
my $size = unpack( 'N', $buf ); ## Or 'V' see perlfunc:pack
my $imgData;
sysread( IN, $size, $imgData );
That's only vaguely equivalent. Your snippet does not show what in, out or more are, so you'll need to work that out for yourself. It looks vaguely as if they are separate input and output handles to a socket stream or pipe, but that's guessing.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
| [reply] [d/l] [select] |
You want pack and unpack. Pack to create the binary data, which you then print to the socket, then you use read to get data back and unpack to turn it in to perl usable scalars. | [reply] |
| [reply] |
If you want to send binary data through a socket, you have to set it up with binmode:
binmode($socketname);
For a full exmaple, read A simple FTP server, see how it calls binmode when the data being FTP'd is image. | [reply] [d/l] |