title: How to use Accept() for multiple connections
body: <p>I'm trying to send <em>http</em> response to the browser at my code (I use virtual machine of linux), when I debug my code I can tell that after one request and response, the <code>accpet()</code> function doesn't wait and continue the procedure even if I did close the socket-fd.</p>
  <p>Does anyone have any idea why is this happening?</p>
  <p>Here is my code:</p>
  <pre><code>while(1){  // infinite loop for requests
  
          if (( user_socket = accept(fsockfd, (struct sockaddr *)&amp;serv_addrf,          // wait for a request from customer and accept new socket
                         (socklen_t*)&amp;addrlenf))&lt;0)
      {
          perror(&quot;accept&quot;);
          exit(EXIT_FAILURE);
      }
      
          while(flag_rec!=1){
              if(recv(user_socket, customer_reply , BUFSIZE , 0) &lt; 0)                  // get the request from customer
      {
          puts(&quot;recv failed my man&quot;);  // in case of failing
      }
          for(int i=0; i&lt;BUFSIZE;i++){
              if(customer_reply[i]=='\r'&amp;&amp;customer_reply[i+1]=='\n'&amp;&amp;customer_reply[i+2]=='\r'&amp;&amp;customer_reply[i+3]=='\n'){ //checking if there is \r\n\r\n
                  customer_reply[i+4]='\0';
                  customer_reply_size=i+4;
                  flag_rec=1;  // it means we received the full http request
                  break;
              }
  
          }
      
  
  
          }
          flag_rec=0;
          if(send(serv_socket,customer_reply,customer_reply_size,0)&lt;0){      // sending the http request to the servers
              puts(&quot;send failed&quot;); // in case of failing
          }
          while(flag_rec!=1){
          if(recv(serv_socket,server_reply,BUFSIZE,0)&lt;0){                    // get the answer message from the servers
              puts(&quot;recv failed mann&quot;);  // in case of failing
          }
          for(int i=0; i&lt;BUFSIZE;i++){
              if(server_reply[i]=='\r'&amp;&amp;server_reply[i+1]=='\n'&amp;&amp;server_reply[i+2]=='\r'&amp;&amp;server_reply[i+3]=='\n'&amp;&amp;server_reply[i+4]=='\0'){ //checking if there is \r\n\r\n
                  server_reply[i+4]='\0';
                  server_reply_size=i+4;
                  flag_rec=1;  // it means we received the full http request
                  break;
                 
              }
  
          }
          }
          flag_rec=0;
          if(send(user_socket,server_reply,server_reply_size,0)&lt;0){
              puts(&quot;send failed&quot;); // in case of failing
          }
          close(user_socket);  // closing the socket after the response
          
          
          
      }
          
  
  </code></pre>