title: Cannot use send() to send .exe in c programming
body: <p>I am building a server-client program with c and having some problen wtih sendina a whole file with  send() and recv() function. I need to send the whole file with these but all these functions can do is send a string. The main problem is with sending the exe or other binary formet data. Should I use htons or htonl func? I dunno how to use those along these as I am merely a noob. </p>
  
  <p>I am stuck with this and love your help. Thanks!!</p>
  
  <p>Here is the server side recv function ::</p>
  
  <pre><code>if (socket_type != SOCK_DGRAM)
      {
  
              fi = fopen (final,"wb");
              retval = recv(msgsock, recv_buf, strlen(recv_buf), 0);
              /*recv_buf[retval] = '\0';
              fprintf (fi,"%s",recv_buf);*/
  
              int i;
              i=atoi(recv_buf);
              char *q;
              q=(char *)malloc(i*sizeof(char));
              retval = recv(msgsock, q, strlen(q), 0);
              //printf ("%s",q);
              fwrite(q,i,1,fi);
              fclose(fi);
  
      }
      else
      {
          retval = recvfrom(msgsock,recv_buf, sizeof(recv_buf), 0, (struct sockaddr *)&amp;from, &amp;fromlen);
          printf("Server: Received datagram from %s\n", inet_ntoa(from.sin_addr));
          printf ("SOCK_DGRAM");
      }
  
      if (retval == SOCKET_ERROR)
      {
          fprintf(stderr,"Server: recv() failed: error %d\n", WSAGetLastError());
          closesocket(msgsock);
          //continue;
      }
      else
          printf("Server: recv() is OK.\n");
  
      if (retval == 0)
      {
          printf("Server: Client closed connection.\n");
          closesocket(msgsock);
              //continue;
      }
      printf("Server: Received %d bytes, data from client\n", retval);
  </code></pre>
  
  <p>The client side sending function :::</p>
  
  <p>void send_command()
  {
      int bytesent;
      FILE *file_out;
      //file_out = fopen(file_path,"rb");
      char str_all[100000];//flag [30]="end";</p>
  
  <pre><code>///////////////////////getsize//////////////
  char fsize[5];
  int filesize;
  file_out = fopen(file_path, "rb");
  fseek(file_out, 0, SEEK_END);
  filesize = ftell(file_out);
  rewind (file_out);
  itoa (filesize,fsize,10);
  /////////////////////////////////////////////
  send (ConnectSocket, fsize, strlen (fsize), 0);
  
  char *r = (char *)malloc (filesize * sizeof(char));
  
  fread(r,filesize,1,file_out);
  bytesent = send( ConnectSocket, r, strlen(r), 0 );
  printf("\nClient: Bytes sent: %ld\n", bytesent);
  fclose (file_out);
  
  /*while (fscanf(file_out,"%s",&amp;str_all) != EOF)
  {
      bytesent = send( ConnectSocket, str_all, strlen(str_all), 0 );
      printf("\nClient: Bytes sent: %ld\n", bytesent);
      //Sleep(500);
  }*/
  
  /*printf("%s",flag);
  send( ConnectSocket, flag, strlen(flag), 0 );*/
  WSACleanup();
  //return 0;
  }
  </code></pre>