Hi everybody,
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:
class PHAL_msg(Structure):
_fields_ = [("Port", c_ushort),
("Size", c_ushort),
("Text", c_wchar_p)]
I would expect I could send this object by just converting it to a bytes object:
Msg_TX = PHAL_msg(Port=PHAL_ADDRESS, Size=PAYLOAD_SIZE, Text='HELLO woRLD!')
socket.send(bytes(Msg_TX))
, but it does not work.
Any idea how this could be done?
Regards