I have a socket server receiving XML files each 500ms and sometimes it goes wrong concatenating more than 1 file as only one file.
char* buf = (char*)MALLOCZ(IP_BUF_SZ);
chrs_read = recv(sockfd, buf, IP_BUF_SZ, 0);
if (chrs_read > 0)
buf = NULL;
while (chrs_read > 0);
The problem is that all files are sent through the same connection, without having a delimiter between them. When the files are sent often, and there is some latency in the network, you can't know where a file ends and a new one begins.
buf, or it could even, if the delimiter is longer than one byte, be received partially in one
recvcall, and the rest follows in the next