Someone to recommend a library to transmit variables over UDP?

Can someone recommend a library to transmit 1-1 variables over UDP, just avoiding the need to get into the guts to chop them into bytes and deserialialise the message on the other side manually?

I would love to be able to define the same structure on both systems (ESPs or Arduinos) and just get something like a...
send_structure() and receive_structure() to deal with.
Who can bring me on the right track?
Thanks for your advice.

I imagine whatever you're using to connect over UDP inherits from the stream class - in which case you can use memcpy(buff, &struct, sizeof(struct)) to put the contents of the struct into a byte array and then use stream.write(buff, sizeof(struct)) to send it via UDP.

Power_Broker:
I imagine whatever you're using to connect over UDP inherits from the stream class - in which case you can use memcpy(buff, &struct, sizeof(struct)) to put the contents of the struct into a byte array and then use stream.write(buff, sizeof(struct)) to send it via UDP.

Thank you. I had the same thought. The method is imho used for EEPROM as well...

So I just would declare a structure containing all my variables (whatever they are?, not strings that have variable lengths, I suppose ?), copy the structure to a char array, sent it via UDP.
On the other side I must declare exactly the same structure, receive the packet into a a char array that will be memcopied into the verbatim structure?

RIN67630:
So I just would declare a structure containing all my variables (whatever they are?, not strings that have variable lengths, I suppose ?), copy the structure to a char array, sent it via UDP.
On the other side I must declare exactly the same structure, receive the packet into a a char array that will be memcopied into the verbatim structure?

Exactly! :slight_smile:

Yeah, you can't use the approach for "S"trings or structs with "S"trings, but it works for pretty much everything else.