newbie sending hex values over UDP socket
Bill Seitz
fluxent at yahoo.com
Thu Sep 9 21:44:16 EDT 2004
I'm working with an outside "partner" to whom I want to send messages
(I want my app to send messages to his server/receiver). He requests
that I use UDP and an "industry standard" for formatting the data
itself.
That format is basically a bunch of hex bytes.
So instead of sending 3 alphanum chars
ri0
I have to send 3 bytes which he explains as being
72 69 30
Now, what the heck should I really be sending? I know he's giving just
a simplified representation.
Am I really looking to send
'726930'
or
'\x72\x69\x30'
or
(something else)?
If I'm aiming for the 2nd format, how do I best generate it? If I'm
going the other direction, it seems like
struct.unpack('sss','\x72\x69\x30')
works OK
But going the other direction doesn't work:
struct.pack('sss','r','i','0') -> 'ri0'
If I'm going for the first format, then I guess
binascii.hexlify('ri0')
is the answer, right?
Sorry for the silly question... I'm trying not to look like a chump
(to that partner)
More information about the Python-list
mailing list