title: Socket fails to accept a client?
body: <p>I am trying to get my feet wet with network programming. I have created a server, that accepts a connection from a web client.</p>
  
  <p>At some point (I can not recall when) it broke, and for the life of me, I can not get it fixed.</p>
  
  <p>Could someone at least provide me with some pointers? (No pun intended)</p>
  
  <p>I have tried all there is, read the whole web, including the <a href="http://www.gnu.org/software/libc/manual/html_node/Accepting-Connections.html" rel="nofollow">gnu</a> <a href="http://www.gnu.org/software/libc/manual/html_node/Socket-Addresses.html#Socket-Addresses" rel="nofollow">c</a> <a href="http://www.gnu.org/software/libc/manual/html_node/Listening.html#Listening" rel="nofollow">library</a> <a href="http://www.gnu.org/software/libc/manual/html_node/Transferring-Data.html#Transferring-Data" rel="nofollow">documentation</a> (I am on linux) but still no luck.</p>
  
  <p><em><strong>EDIT:</em> Description of the problem:</strong> My client software manages to connect, however the server software doesn't report on that, and seems to get stuck at the accept() function.</p>
  
  <p>My code:</p>
  
  <pre><code>#include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include "lib/error.h"
  #include &lt;string.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;time.h&gt;
  
  int main(int argc, char *argv[])
  {
      int socketfd = 0, connfd = 0; // socket, and connection file descriptors
      struct sockaddr_in serv_addr; // struct that will get filled with host info
      struct sockaddr_in cli_addr; // struct that will get filled with peer info
      int status; // Used for various status controling and error messaging throughout the program
  
      char sendBuff[1025]; // buffer to allow for storage of items to be sent
      socklen_t cli_size = sizeof(cli_addr);
      time_t ticks;
  
      socketfd = socket(AF_INET, SOCK_STREAM, 0); // Creating a socket
      if (socketfd == -1) error("Failed to create socket.", 4);
  
      memset(&amp;serv_addr, '0', sizeof(serv_addr)); // zeroing out the location of serv_addr
      memset(&amp;cli_addr, '0', sizeof(cli_addr)); // zeroing out the location of serv_addr
      memset(sendBuff, '0', sizeof(sendBuff)); // zeroing out the locaiton of sendBuff
  
      serv_addr.sin_family = AF_INET;
      serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
      serv_addr.sin_port = htons(5000);
  
      status = bind(socketfd, (struct sockaddr *) &amp;serv_addr, sizeof(serv_addr));
      if (status == -1) error("Failed to bind socket.", 4);
  
      listen(socketfd, 10);
  
      while(1)
      {
          connfd = accept(socketfd, (struct sockaddr *) &amp;cli_addr, (socklen_t *) &amp;cli_size);
          if (connfd == -1) error("Failed during accepting the peer connection at socket.", 3);
  
          printf("Client connected: %d:%d", cli_addr.sin_addr.s_addr, cli_addr.sin_port);
  
          close(connfd);
          sleep(1);
      }
  
      return 0;
  }
  </code></pre>