in C recvfrom
can be used to read UDP messages form a socket as such:
int length = recvfrom(socket, buffer, max_length, 0, NULL, 0);
max_length
only tells the maximum number of bytes the buffer can hold, and not the actual length of course.
Assume my message is the following and is sent with sendto
:
char *message = "hi";
sendto(sock, message, strlen(message), 0, NULL, 0);
Now recvfrom
will immediately stop reading after the i
character is received. length
will be set to 2.
How does it know when to stop?
does sendto
append any data to the packet with result of strlen saying what the data length is? or does it look for null terminating char?