title: UDP Socket Set Timeout
body: <p>I am trying to set a 100ms timeout on a UDP Socket.  I am using C.  I have posted relavent pieces of my code below.  I am not sure why this is not timing out, but just hangs when it doesn't receive a segment.  Does this only work on sockets that are not bound using the bind() method?</p>
  
  <pre><code>#define TIMEOUT_MS      100     /* Seconds between retransmits */
  
  if ((rcv_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) &lt; 0)
      DieWithError("socket() failed");
  
  if ((rcv_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) &lt; 0)
      DieWithError("socket() failed");
  
  //set timer for recv_socket
  static int timeout = TIMEOUT_MS;
  setsockopt(rcv_sock, SOL_SOCKET, SO_RCVTIMEO,(char*)&amp;timeout,sizeof(timeout));
  
  if(recvfrom(rcv_sock, ackBuffer,sizeof(ackBuffer), 0,
         (struct sockaddr *) &amp;servAddr2, &amp;fromSize) &lt; 0){
      //timeout reached
      printf("Timout reached. Resending segment %d\n", seq_num);
      num_timeouts++;
  }
  </code></pre>