I am programming an application to send data using UDP sockets with Python 3.1.
The command socket.send requires data in bytes format.
The problem I am having is that the package I have to send has three different fields, the first one contains a 16 bits integer variable (c_ushort) and so does the second field whereas the third one is an string whose length can go up to 900 characters.
I decided then to create an struct that contains these three fields:
Expand|Select|Wrap|Line Numbers
- class PHAL_msg(Structure):
- _fields_ = [("Port", c_ushort),
- ("Size", c_ushort),
- ("Text", c_wchar_p)]
Expand|Select|Wrap|Line Numbers
- Msg_TX = PHAL_msg(Port=PHAL_ADDRESS, Size=PAYLOAD_SIZE, Text='HELLO woRLD!')
- socket.send(bytes(Msg_TX))
Any idea how this could be done?
Regards