The title is a bit exaggerated, but I want MAX clients that I can possibly have and I don’t want threads unless I need them.
Do I need a thread to accept()
TCP connections?
Do I need threads for TCP recv()
? If each client’s recv()
is NOT ran on a separate thread, how will I differentiate them if only part of a TCP message arrived (say 30 of 111 bytes)? Which client does this incomplete recv()
belong to?
Lastly, what is the least amount of server-side TCP sockets needed for this? Two? One for accept()
and one for recv()/send()
?
int main()
{
thread t1(listen_accept);
thread t2(recv_100k_clients);
while(true) {Sleep(1000);};
return(0);
}