title: writing binary data to a file using c++ , after receiving from socket
body: <p>I am trying to write a c++ code which read from a file (any type) and write the file data (binary data) on the socket , so the receiver must take this data and create a file , i should see the same data with the same format , the problem is the data is still binary and written to the file as binary data !
  if a tested the code without sending on a network , it will work well !
  any idea ?
  thanks in advance .
  note , i am using Ubuntu 11.10 if it affects this issue ..</p>
  
  <p>Here is the code, on the client side:</p>
  
  <pre><code>filer=fopen("a.doc","rb"); 
  fseek (filer , 0 , SEEK_END); 
  long size; 
  size = ftell (filer); 
  rewind (filer); 
  buffer = (char*) malloc (sizeof(char)*size); 
  numr=fread(buffer,1,size,filer); 
  fclose(filer); //some socket code 
  char buffer2[size]; 
  strcpy(buffer2 , buffer);
  n = write(sockfd,buffer2,size); 
  </code></pre>
  
  <p>and for the server side : </p>
  
  <pre><code>n = read(sock,buffer,length);
  FILE * filew;
  int numw;
  filew=fopen("acopy.doc","wb");
  numw=fwrite(buffer,1,len,filew);
  fclose(filew);
  </code></pre>