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.
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.
Then I've searched over the internet and found out that it is possible to use both TCP and UDP alongside each other.
I've tried to use the UDP protocol but I didn't have any major progresses.
My problem is I use both recv() and recvFrom() in a while loop like this:
while (true) { buflen = recv(clientS, buffer, 1024, NULL); if (buflen > 0) { // Send the received buffer } else if (buflen == 0) { printf("closed\n"); break; } buflen = recvfrom(udpS, buffer, 1024, NULL, (struct sockaddr*)&_s, &_size); But the recvFrom() blocks. I think I haven't done the job properly but I couldn't find out how to do it.
Here Server in C accepting UDP and TCP connections I found a similar question but the answers were just explanations and there were no sample codes to demonstrate the point clearly.
Now I need you to help me undestand clearly how to receive data from both TCP and UPD connections.
Any help is appreciated.
selectorpollor something similar, like epoll or kqueue (though using TCP and UDP together usually isn't a great idea anyway as TCP induces packet loss).selectorpoll.poll()orepoll(), onlyselect(), and also non-standardWSAAsyncEvent()andWSAAsyncSelect()extensions.