I've been using these read and write functions (provided by @alk).
The problem is that I don't know how to correctly send the uint16_t data_size;
.
Here is my actual code to send a general example buffer:
uint16_t data_size;
int retry_on_interrupt = 0;
char buffer[] = "Hello world!";
data_size = (uint16_t) sizeof(buffer);
/* sending data_size */
writen(socket, data_size, 2, retry_on_interrupt);
/* sending buffer */
writen(socket, buffer, sizeof(buffer);
And here is my actual code to receive a general example buffer:
/* receiving data_size */
readn(socket, &data_size, 2);
/* receiving buffer */
readn(socket, buffer, data_size);
But this is not working, I think because writen
requires a const char *
, instead I'm using a uint16_t
...
How should these calls be? Thanks.