title: recv() goes into infinite loop
body: <p>I am trying to send a file 4 bytes at a time , if the length of the contents of the file is not divisible by 4 i add some extra space and the i send it </p>
  
  <p>When i send some string it's working but for some string  recv() is going into infinite loop </p>
  
  <p>Client.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;sys/types.h&gt;
  
  
  using namespace std;
  
  int main(){
  
  int ssock , csock ; 
  struct sockaddr_in server ;
  
  server.sin_family = AF_INET ; 
  server.sin_port = htons(8088);
  server.sin_addr.s_addr = inet_addr("127.0.0.1");
  
  
  ssock = socket (AF_INET,SOCK_STREAM,0);
  if (ssock == -1 ) {
                  cout &lt;&lt; " Error " ; return 0 ;
          }
  
  connect(ssock , (sockaddr *)&amp;server ,sizeof(server));
  /*void *buff ; 
  int len = recv(ssock , buff ,1024,0 );
  int  *ptr =  (int *)buff ;
  cout &lt;&lt; *ptr ;*/
  void * buff ;
  int len;
  while(len = recv(ssock , buff ,4,0 )){
          cout&lt;&lt;(char *)buff&lt;&lt;len&lt;&lt;"\n";
  
  
  }
  
  
    return 0 ;
  }
  </code></pre>
  
  <p>server.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;fstream&gt;
  #include &lt;cstring&gt;
  #include &lt;unistd.h&gt;
  
  
  using namespace std;
  
  int main(){
  
  int ssock , csock ; 
  struct sockaddr_in server ;
  
  server.sin_family = AF_INET ; 
  server.sin_port = htons(8088);
  server.sin_addr.s_addr = inet_addr("127.0.0.1");
  
  
  ssock = socket (AF_INET,SOCK_STREAM,0);
  if (ssock == -1 ) {
                  cout &lt;&lt; " Error " ; return 0 ;
          }
  
  bind(ssock , (sockaddr *)&amp;server ,sizeof(server));
  listen(ssock,5);
  socklen_t size  = sizeof (server );
  fstream fin("text.txt",ios::in);
  string s((istreambuf_iterator&lt;char&gt;(fin)),istreambuf_iterator&lt;char&gt;());
  fin.close();
  //cout&lt;&lt;s;
  int len = s.size();
  if(len % 4 != 0 ) {
          s.pop_back();
          int i = len % 4 ;
          i =  4 - i ;
          while(i){s.push_back(' ');i--;}
          s.push_back('\0');
  }
  cout&lt;&lt;s&lt;&lt;"\n"&lt;&lt;s.size()&lt;&lt;"\n";
  
  while(csock = accept(ssock,(sockaddr *)&amp;server ,&amp;size)){
  
          cout&lt;&lt;"\n Connection Accpeted \n" ;
          /*int s = 172;
          send(csock , (void *)&amp;s, sizeof(s),0);*/
         int i = 0;
  
          i = 0 ;
          while(i &lt;= s.size()){
          string temp =s.substr(i,4);
          cout&lt;&lt;temp&lt;&lt;"\n";
          cout&lt;&lt;send(csock,(void *)temp.c_str() ,4,0);
          i+=4;
          }
  
          close(csock);
  
  
  
  
  
  }
  
    return 0 ;
  }
  </code></pre>
  
  <p>Is there any issues while sending or while receiving , kinda stuck at this point for sometime . </p>