hayyan85
August 21st, 2009, 03:59 PM
Hi whenever I try to receive a file the data is appended at the end of the file. In vb we use to cater this by using doevents
so that a new packet is sent
here is the code:
Transmitter:
FILE *fp = fopen("c:\\Send.txt", "rb");
while(!feof(fp))
{
if ( (bytes_read = fread(&buff, sizeof(char), CHUNK , fp)) > 0 )
{
//SEND FILE
Bytes_Sent=send(myclient, buff, bytes_read, 0);
}
}
fclose (fp);
send(myclient, "End", 3, 0);
closesocket(myclient);
WSACleanup();
Receiver:
cout << "Data Receive - Thread Started" << "\n";
FILE *fp1 = fopen("c:\\copy.txt", "wb");
while(1)
{
long myno = recv(client,mybuff,sizeof(mybuff),0);
if (strncmp(mybuff,"End",3)==0)
{
cout << "file Transfer Completed Succesfully";
fclose (fp1);
}
else
while (myno != -1 && myno > 0)
{
Written = fwrite(myptr, sizeof(char), myno, fp1);
myno = myno - Written ;
}
}
--------------------------------------------------------------------------------------
The word End is appended at the end of the file
How can i solve this problem.. Plz Help
so that a new packet is sent
here is the code:
Transmitter:
FILE *fp = fopen("c:\\Send.txt", "rb");
while(!feof(fp))
{
if ( (bytes_read = fread(&buff, sizeof(char), CHUNK , fp)) > 0 )
{
//SEND FILE
Bytes_Sent=send(myclient, buff, bytes_read, 0);
}
}
fclose (fp);
send(myclient, "End", 3, 0);
closesocket(myclient);
WSACleanup();
Receiver:
cout << "Data Receive - Thread Started" << "\n";
FILE *fp1 = fopen("c:\\copy.txt", "wb");
while(1)
{
long myno = recv(client,mybuff,sizeof(mybuff),0);
if (strncmp(mybuff,"End",3)==0)
{
cout << "file Transfer Completed Succesfully";
fclose (fp1);
}
else
while (myno != -1 && myno > 0)
{
Written = fwrite(myptr, sizeof(char), myno, fp1);
myno = myno - Written ;
}
}
--------------------------------------------------------------------------------------
The word End is appended at the end of the file
How can i solve this problem.. Plz Help