[Tutor] Send binary/hex data to a TCP socket
ke7fxl at gmail.com
Thu Jan 25 02:51:23 CET 2007
I need to send a server at the other end of a socket a 36 byte
"frame", where each byte represents a specific field in the custom
data structure. (If there are any Ham operators reading this, I'm
talking about the AGW Packet Engine)
The documentation for the server says to initialize each field to a
binary zero(0x00). How do I get a binary zero in Python? The next
step is to send this all to the server and subsequently receive a
similarly formated frame.
A very basic frame looks something like this(modified from documentation):
|00 00 00 00 4D 00 00 00 00 00 00 00 00 00 00 00 |....M...........
|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................
|00 00 00 00 |....
My problem is that hex(0) return '0x0' and hex(ord('M')) returns
'0x4d'. If I concatonate these all together then the socket receives
109 bytes instead of 36. The documentation examples are in C++, so
they are little help to me. The examples make use of the MoveMemory
function for building the frames, but I'm clueless what that does.
Pseudo code for the frame above:
l = 
for i in xrange(36):
d=d.join(l) #I need some other data type to send besides a string!
sock.send(d) #send the 36 bytes to the socket
Any pointers or references would be greatly appreciated.
More information about the Tutor