1: The server copy the file size into the buffer and send it:
snprintf(t_buf, 255, "%" PRIu32, fsize);
if(send(f_sockd, t_buf, sizeof(t_buf), 0) < 0){
perror("error on sending file size\n");
onexit(f_sockd, m_sockd, 0, 2);
}
2: The client receives the file size and put it into fsize:
if(recv(f_sockd, t_buf, sizeof(t_buf), 0) < 0){
perror("error on receiving file size");
onexit(f_sockd, 0 ,0 ,1);
}
fsize = atoi(t_buf);
----------------- The code above makes my program working perfectly!
The problem happens if i write this code instead of the previous one:
1: The server send fsize:
if(send(f_sockd, &fsize, sizeof(fsize), 0) < 0){
perror("error on sending file size\n");
onexit(f_sockd, m_sockd, 0, 2);
}
2: The client receives fsize:
if(recv(f_sockd, &fsize, sizeof(fsize), 0) < 0){
perror("error on receiving file size");
onexit(f_sockd, 0, 0, 1);
}
Where uint32_t fsize;
and char t_buf[256];
.
The problem is that with the first method all work but with the second method the client doesn't receive all file but only a piece of it. What is wrong with this code?
Thanks!