locked
Simple Question ::: Need Help with Incomplete File Transfer RRS feed

  • Question

  • Hi , I am currently having a problem during file receiving . The code for the receiver which I am using is given below.

    char mybuff[1024];

    FILE *fp1 = fopen("c:\\copy.txt", "wb");

    myno = recv(client,mybuff,sizeof(mybuff),0);

                      if (myno > 0 && myno !=-1)
                       {
                            while (myno != -1 && myno > 0)
                             {
                                  Written = fwrite(mybuff, 1,myno, fp1); ///////Line 1
                                  myno = myno - Written ;
                             }
                             myno = 0;
                       }

    The Problem is the tranfer process remain incomplete (The final part does not get written in the file).The transmitters code is working and I know the receiver receives the data (by using - cout << Mybuff ). Then why does the complete file writing process does not work (remains incomplete) most of the times ?? . I tried to handle the problem by Introducing Sleep(800)  after line 1 which seems to have temporaryly solved the problem. But still I need to know why it isnt working. Furthermore I am also attaching the transmitter code along with this. I am using Borland C++ 5.02

    Transmitter Code:
      FILE *fp = fopen("c:\\Send.txt", "rb");
                                   while(!feof(fp))
                                     {
                                        bytes_read = fread(&buff, sizeof(char), CHUNK , fp) ;
                                           {
                                               //SEND FILE
                                               Bytes_Sent=send(myclient, buff, bytes_read, 0);
                                           }

                                     }
                                     fclose (fp);

    Could You guys please please try to help me out ..  I really need to solve this problem

    Sunday, August 23, 2009 10:43 AM

All replies

  • I don't know, but this isn't the right forum.
    Thursday, March 18, 2010 1:36 AM