Hello Perl gurus,
I thought I would post a summary of what I found on this question I asked the other
day. The original question was how to send a binary stream of data
across a socket from the TCP client end. How to use pack() and
syswrite() were some of my questions. Well I did end up using pack
to create a byte stream in binary representation,
and was able to send 10 bytes of data below, byte-by-byte, from a Red
Hat Linux 7.2 machine (big-endian order) to a big-endian TCP server. I
used the first two bytes to specify the length of the string.
Here is what the code looks like. I hope this helps anyone that needs
to implement something like this in the future. Now to the receiving
end. The fun begins!
#################################################
# Let's take a closer look at the actual message
#################################################
$Len1 = 0x00;
$Len2 = 0x0A;
$SVCA = 0x96;
$DVCA = 0xDF;
$CTRL = 0x40;
$STAT = 0x00;
$FUNCID = 0x83;
$ACCESS = 0x04;
$RGB1 = 0x00;
$RGB2 = 0x00;
$RGB3 = 0x00;
$RGB4 = 0x0A;
#################################################
#Building the bytestream
$bytestring = pack('C*', $Len1, $Len2, $SVCA, $DVCA, $CTRL, $STAT, $FUNCID, $ACCESS,
$RGB1, $RGB2, $RGB3, $RGB4);
$len = length($bytestring);
#######
# Here is the routine that sends to the socket...Needs work
#######
$offset = 0;
$bytes_to_write = $len - $offset;
$bytes_written = 0;
while ($bytes_to_write) {
$bytes_written = syswrite ($socket, $bytestring, $bytes_to_write, $offset);
$offset += $bytes_written;
$bytes_to_write -= $bytes_written;
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]