kris.c 0 Newbie Poster

hi,
I have written small server/client programs to transfer files from one pc to another on the network..
Naturally ,I have used the send() and recv() functions on both sides to send and receive buffer.

I am transferring the characters one at a time in any given file into the buffer and then sending the buffer.


sending side:

FILE *fp;
fp=fopen("filename","r");
while((c=getc(fp))!=EOF)
{
buf[i]=c;
i++;
}
buf[i]='\0';
fclose(fp);
send(sockfd,buf,sizeof(buf),0);

receiving side:

recv(sockfd1,buf1,sizeof(buf1),0);
  FILE *fp;
  fp=fopen("filename","w");
  fprintf(fp,"%s",buf1);
  fclose(fp);

This does help in reproducing the exact image of the file on another pc for smaller files.. but,I have noticed the data being currupted for larger files ( >8000 chars).
I have to send only data files with some formatting.
Is this method good enough?
Is there any other way of doing it?
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.