need help with sending file
With my program you are supposed to be able to send a file from one computer to another, but this is whats wrong:
The file size is 6846 bytes, both the sender and receiver knows that and when i cout the size the value is correct on both machines. However the file which i receive is 6941 bytes. The last character of the text-file im sending is repeated 95 times in the end of the received file. Here are the code parts which are important:
Code:
//the receiver
char rcv_byte[1];
int i = 0;
while(i < size) //the value of size is correct, I've checked
{
bytes_rcv = recv(newFD, rcv_byte, 1, 0); //receive one byte at a time
fout.write(rcv_byte, 1); //write to the file
tot_recv += bytes_rcv;
i++;
}
//the sender
char send_byte[1];
int i = 0;
while(i < size)
{
fin.read(send_byte, 1);
bytes_sent = send(sockFD, send_byte, 1, 0);
tot_sent += bytes_sent;
i++;
}
the end of the file i'm sending looks like this:
***321
the end of the received file looks like this:
***32111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111 1
Does anyone know what could be wrong?
I'm using win98 on one machine an XP on the other, borland command line tools 5.5.
Apart from the error mentioned there are no other errors in the program.