title: How to use both TCP and UDP in one application in c++
body: <p>I'm developing a server-client project based on Winsock in c++. I have designed the server and the client sides so that they can send and receive text messages and files as well.</p>
  
  <p>Then I decided to go for audio communication between server and client. I've actually implemented that however I've figured it out that I've done everything using TCP protocol and that for the audio communication it is better to use UDP protocol.</p>
  
  <p>Then I've searched over the internet and found out that it is possible to use both TCP and UDP alongside each other.</p>
  
  <p>I've tried to use the UDP protocol but I didn't have any major progresses. </p>
  
  <p>My problem is I use both recv() and recvFrom() in a while loop like this:</p>
  
  <pre><code>while (true)
  {
      buflen = recv(clientS, buffer, 1024, NULL);
  
      if (buflen &gt; 0)
      {
          // Send the received buffer
      }
      else if (buflen == 0)
      {
          printf("closed\n");
          break;
      }
  
      buflen = recvfrom(udpS, buffer, 1024, NULL, (struct sockaddr*)&amp;_s, &amp;_size);
  </code></pre>
  
  <p>But the recvFrom() blocks. I think I haven't done the job properly but I couldn't find out how to do it.</p>
  
  <p>Here <a href="https://stackoverflow.com/questions/22691360/server-in-c-accepting-udp-and-tcp-connections">Server in C accepting UDP and TCP connections</a> I found a similar question but the answers were just explanations and there were no sample codes to demonstrate the point clearly.</p>
  
  <p>Now I need you to help me undestand clearly how to receive data from both TCP and UPD connections.</p>
  
  <p>Any help is appreciated.</p>