Ok, this comes straight from my web server:
Code:
while (!SERVER_STOP)
{
SFD_New = accept(SFD_Listen, (struct sockaddr *) &ClientAddress, &Size);
DWORD dwThreadId;
HANDLE hThread;
// Create a structure of type ARGUMENT to be passed to the new thread
ARGUMENT Argument;
Argument.CLA = ClientAddress;
Argument.SFD = SFD_New;
// CreateThread and process the request
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
ProcessRequest, // thread function
&Argument, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
if (hThread != NULL)
{
CloseHandle( hThread );
}
}
This is how it works: Accept waits for a connection from a client. When it gets a connection, it puts the socket for the client in SFD_New. Then it creates a new thread to handle the connection, and gets back to accept()ing. This can handle multiple clients because a new thread is created each time, allowing the server to get back to listening.
If I was to take out the new thread creation, so It looked like this:
Code:
while (!SERVER_STOP)
{
SFD_New = accept(SFD_Listen, (struct sockaddr *) &ClientAddress, &Size);
// Do some stuff with SFD_New.
closesocket(SFD_New);
}
It would not accept a new client UNTIL the first one had finished processing. Get it now? So, if your Admin ports were like the second example, they could only have one connection at a time. But if they were like the first, they could have multiple