> I'm trying to accept at least 1000 clients, i dont know if multithreading is the answare!
It isn't.
A single threaded program using select() will be a lot (no seriously, a
LOT) easier for you to get working.
I mean you've already thrown in a mutex into your code without understanding why (or even if) it was necessary. Unnecessary mutexes will just eat into the performance. Necessary ones you miss will result in
https://en.wikipedia.org/wiki/Heisenbug (or more formally
https://en.wikipedia.org/wiki/Race_condition ) problems that will screw with your mind.
No real machine you're likely to have will have anywhere near 1000 real cores, so 1000 threads are going to spend most of their time in expensive context switches.
> I saw some tutorials on YT using SELECT() and FD_SET to handle multiple clients,
> but i heard it can accept a specific amount of clients , i think 60-70 .
Then read the actual manual, not some YT wibbler.
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select
Four macros are defined in the header file Winsock2.h for manipulating and checking the descriptor sets. The variable FD_SETSIZE determines the maximum number of descriptors in a set. (The default value of FD_SETSIZE is 64, which can be modified by defining FD_SETSIZE to another value before including Winsock2.h.) Internally, socket handles in an fd_set structure are not represented as bit flags as in Berkeley Unix. Their data representation is opaque. Use of these macros will maintain software portability between different socket environments. The macros to manipulate and check fd_set contents are:
|
For info, Linux has a FD_SETSIZE of 1024, so this seems a good place to start.
Oh, and set your IDE to use 4 spaces for indentation, not hard tabs.
It might look reasonable on your screen, but sooner or later, something somewhere will make a dogs dinner out of your code by not interpreting tabs the same way your IDE does.
> listen(s_socket, MAXCLIENTS);
The backlog is not the number of clients.
It's the number of clients you're expecting to join in some small moment of time before you get around to doing an accept().