Hi i have trouble with the following piece of code.The sender sends a file ,a line at a time to the rx.After sending the file the sender closes the socket,therby closing the connection.But rx is not able to receive the entire file.The sender sender sends the file correctly.But the receiver is not able to catch up.The rest of the program works fine.The program doesnt stall.
fp=fopen(buf,"r"); //open file
while(fgets(frame,70,fp)!=NULL)
{
c=send(s,frame,strlen(frame)+1,0);
printf("%s frame sent\n",frame);
//memset(frame,0,70);
}
sleep(2);
close(i); //close socket after sending file.. initiate break
FD_CLR(i,&master);
receiver:
while(1)
{
printf("receiving file \n");
c=recv(soc,buffer,70,0);
printf("received (file bytes) % d \n",c);
if(c<=0) //responds to closure of connection
{
close(soc);
printf("closed socket \n");
break;
}
else
{
fp=fopen(query,"a+");
fprintf(fp,"%s ",buffer);
printf("%s ",buffer);
fclose(fp);
memset(buffer,0,70);
}
}