Your problem is in the use of
unpack("B*", ...).
The
unpack there takes raw binary data and turn it into
a human-readable string of 1s and 0s.
The pack you
are using already returns a raw data that is probably
suitable for sending over the socket.
(agh! see
update below.)
You should probably be using syswrite or you should
turn off buffering.
update:
Oops, mental error, the pack format's wrong. See
node below.