title: using select to waiting for data on a client socket
body: <p>Any ideas why when the server writes a socket while the client is waiting on select, select never finishes?</p>
  
  <p>I am using c to communicate between sockets. My client connects to my server fine. </p>
  
  <pre><code>socket_desc=socket(AF_INET,SOCK_STREAM,0);//create the socket descriptor
  client-&gt;address.sin_addr.s_addr = inet_addr(ipAddress);
  client-&gt;address.sin_family = AF_INET;
  client-&gt;address.sin_port = htons(port);
  
  bind(socket_desc,&amp;address,sizeof(address));
  connect(socket_desc, &amp;address, sizeof(address));
  </code></pre>
  
  <p>When I use recv to block and listen for data, everything works fine:</p>
  
  <pre><code>int bytesRead = 1;
  while(bytesRead){
      int bufsize=1024;        
      char *buffer=malloc(bufsize);
      bytesRead = recv(socket_desc, buffer, bufsize, 0);
      printf("CLIENT RECV: %s", buffer);
  }
  </code></pre>
  
  <p>If I try to use select, it doesn't seem to read any data. If I add STDIN to the fd_set, I can force it to read from the socket, but select doesn't seem to get triggered from the socket_desc reading in data...?</p>
  
  <pre><code>int running = 1;
  while(running){
      /* wait for something to happen on the socket */
      struct timeval selTimeout;
      selTimeout.tv_sec = 2;       /* timeout (secs.) */
      selTimeout.tv_usec = 0;            /* 0 microseconds */
      fd_set readSet;
      FD_ZERO(&amp;readSet);
      FD_SET(STDIN_FILENO, &amp;readSet);//stdin manually trigger reading
      FD_SET(socket_desc, &amp;readSet);//tcp socket
  
      int numReady = select(3, &amp;readSet, NULL, NULL, &amp;selTimeout);
              //IT ONLY GETS PAST SELECT ON RETURN FROM THE KEYBOARD
      if(numReady &gt; 0){
          char buffer[100] = {'\0'};
          int bytesRead = read(socket_desc, &amp;buffer, sizeof(buffer));
          printf("bytesRead %i : %s", bytesRead, buffer);
          if(bytesRead == 0){
              running = FALSE;
              printf("Shutdowning client.\n");
  
          }
      }
  </code></pre>