1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
char nom[50] = "fichierRecubis.txt";
FILE *fichier_src = fopen (nom, "wb");
if (fichier_src == NULL)
{
perror ("fopen() ");
exit (0); //exit(EXIT_FAILURE);
}
int BUFZISE=1024;
char *buffer = malloc(BUFZISE); // Allocation de la mémoire
int bytesrecu=0;
int totalbytes=0;
/* Si l'on reçoit des informations : on les affiche à l'écran */
while(totalbytes<2503)
{
bytesrecu=recv(sock, buffer, BUFZISE, 0);
/* Si l'on reçoit des informations : on les affiche à l'écran */
if(bytesrecu!= SOCKET_ERROR)
{
totalbytes = totalbytes + bytesrecu;
fwrite(buffer,BUFZISE, 1,fichier_src);
}
printf("test : %d octets \n", totalbytes);
}
fclose(fichier_src);
}
/* sinon, on affiche "Impossible de se connecter" */
else
{
printf("Impossible de se connecter\n");
} |