0

サーバーからファイルをダウンロードする必要がある課題があります..しかし、データが送信される場合と送信されない場合があります!!

サーバー:

printf("Reading and sending the File.\n");
memset(buff, 0, sizeof(buff));
while((n=read(fp, buff, 1024)) > 0 )
{   
    printf ("%s \n", buff); //no problem, coz it reads the file correctly  
    write(connfd, buff, n); 
    memset(buff, 0, sizeof(buff));
}

クライアント:

printf("Start downloading the file.\n");
bzero(&data,sizeof(data));
n = 0;
while (1)
{
    n = read(sockfd , data, 1024);
    if (n > 0)
    {
         data[n] = 0;
         r = write (fp, data, n);
         if (r < 0)
         {
             printf("Write to file !!!!!!\n");
         exit(1);
         }
    }
    printf ("\n%s\n", data);
    bzero (&data, sizeof (data));
    if (n < 1024)
        break;
}
printf("Done downloading the file\n");
close (fp);
4

2 に答える 2