Recently, to do a socket server, you need to receive the group broadcast text, and analysis processing. One of the problems involved is that the message to be sent is in the form of a string, similar to "Hello World".
From the Wireshark intercepted messages, are 16 binary data, thought must be converted to the type to send, need to convert to 16 binary strings, similar to "0X\A00X\C30X\B4" and so on.
But later found that the direct transmission of data is OK, it should be sent when the data will be transcoded.
Do not know the time, the online search, found that we recommend the module is BINASCII, view Help
Several methods are as follows:
FUNCTIONS
A2b_base64 (...)
(ASCII), bin. Decode a line of base64 data
ASCII to bin data, decoding a base64 of data--no matter what I need
A2b_hex (...)
A2b_hex (HEXSTR), S; Binary data of hexadecimal representation.
Hexadecimal representation of binary data-required because the final data is to be in the form of a 16 binary string
Hexstr must contain an even number of hex digits (upper or lower case).
This function is also available as "unhexlify ()"
The parameter hexstr must be an even number of 16 binary Loadline--required, two 16 binary loadline to form an ASCII code word
A2B_HQX (...)
ASCII-bin, done. Decode. HQX coding
Just ignore it.
A2B_QP (...)
Decode A string of qp-encoded data
Just ignore it.
A2b_uu (...)
(ASCII), bin. Decode a line of uuencoded data
Just ignore it.
B2a_base64 (...)
(bin), ASCII. Base64-code Line of data
B2a_hex (...)
B2a_hex (data), S; Hexadecimal representation of binary data.
Look at this translation: binary data 16 binary representation, seemingly the same as above.
Try it first:
>>>t = Binascii.b2a_hex (' Hello World ')
' 68656C6C6F20776F726C64 '
>>> Binascii.a2b_hex (t)
' Hello World '
>>> Binascii.a2b_hex ("e4bda0e5a5bde59564")
' \XE4\XBD\XA0\XE5\XA5\XBD\XE5\X95D '
The first function is to encode a string into a 16 string
The second function is to add a 16 binary string to the 16 notation
"Python" string, 16 binary data processing