I have to send multiple variables types over an udp socket: an int array and a char. I would like to send it on the same udp packet. What is the standard solution? Convert everything to bytes or something similar?
I'm using: sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
My code is something like:
int buffer[100];
char flag = '0';
int i = 0;
for (i = 0; i < 50; i++) {
buffer[i] = i * 2;
}
if (sendto(s, buffer, sizeof(buffer), 0, (struct sockaddr *) &si_client, slen) == -1 ){
//error
}
//rest of the program