title: C++ How to exit out of a while loop recvfrom()
body: <p>I'm trying to create a UDP broadcast program to check for local game servers, but I'm having some trouble with the receiving end. Since the amount of servers alive is unknown at all times, you must have a loop that only exits when you stop it. So in this bit of code here:</p>
  
  <pre><code>while(1) // start a while loop
         {
       if(recvfrom(sd,buff,BUFFSZ,0,(struct sockaddr *)&amp;peer,&amp;psz) &lt; 0) // recvfrom() function call
          {
              cout &lt;&lt; red &lt;&lt; "Fatal: Failed to receive data" &lt;&lt; white &lt;&lt; endl;
              return;
          }
       else
       {
              cout &lt;&lt; green &lt;&lt; "Found Server :: " &lt;&lt; white;
              cout &lt;&lt; yellow &lt;&lt; inet_ntoa(peer.sin_addr), htons(peer.sin_port);
              cout &lt;&lt; endl;
     }
         }
  </code></pre>
  
  <p>I wish to run this recvfrom() function until I press Ctrl + C. I've tried setting up handlers and such (from related questions), but they're all either too complicated for me, or it's a simple function that just exits the program as a demonstration. Here's my problem:
  The program hangs on recvfrom until it receives a connection (my guess), so, there's never a chance for it to specifically wait for input. How can I set up an event that will work into this nicely? </p>
  
  <p>Thanks! </p>