M
michelle
Hi, I am trying to transfer a binary file from a client program to the
server, so on the server side I am using recv() to receive the binary
data to the buffer and then write to a file. The follwoing is my
code. Somehow, the newly transfered file is different from the
original file. I don't know if the error is at recv() or fwrite().
For receving, I already check that the bytes being sent equals to the
btyes being received. So anyone knows what's wrong with my code?
Thanks.
char buf[length]; (length is how many bytes of data)
fid=fopen("dataio_testing.bit", "wb"); (open a file to write binary
data)
//this part is right, coz it receive right amount of bytes.
while (bytes != length) {
bytes += recv(clisock, buf, length-bytes, 0);
}
num=fwrite(buf, 1, bytes, fid); (write data into file, in unit of
bytes)
fclose(fid);
server, so on the server side I am using recv() to receive the binary
data to the buffer and then write to a file. The follwoing is my
code. Somehow, the newly transfered file is different from the
original file. I don't know if the error is at recv() or fwrite().
For receving, I already check that the bytes being sent equals to the
btyes being received. So anyone knows what's wrong with my code?
Thanks.
char buf[length]; (length is how many bytes of data)
fid=fopen("dataio_testing.bit", "wb"); (open a file to write binary
data)
//this part is right, coz it receive right amount of bytes.
while (bytes != length) {
bytes += recv(clisock, buf, length-bytes, 0);
}
num=fwrite(buf, 1, bytes, fid); (write data into file, in unit of
bytes)
fclose(fid);