Phil
There are a number of ways to handle this.
A good book to read about servers is INTERNETWORKING WITH TCP/IP
VOLUME III by Douglas E. Comer and David L. Stevens.
Without going too much into detail I'll say that there are two
basic server designs: (There are more, but the ones I seem to use
the most are)
1) Single Process Concurrent Connection Server
2) Multiple Process Single Connection Server
1: One single process or thread accepts a connection,
and maintains a "Connection List" of some sort to process
data xmitted from clients.
2: One single process or thread accepts connection and hands
it off to another process by forking(). This child process
then handles this single connection.
Since there has been some difficulties with sockets between threads,
I strongly urge you to use method 1.
--A deeper look into Method 1--
Basically, your DOZ server waits and Listens for incoming connections
and processes any messages by established connections.
This can be done conveniently by using the messages passed to you via
winsock. Basically, the message determines the action:
OnFD_ACCEPT()
{
Add client to connection list
.
.
.
}
OnFD_READ()
{
Find client in connection list
(BTW wParam from this message is the socket in question :)
.
.
.
}
OnFD_WRITE()
{
Find Client in connection list
Write to em if necessary
}
OnFD_CLOSE()
{
Find Client in connection list
Delete Client from connection list
.
.
.
}
Now that you have these message handlers set up,
you MUST MUST MUST MUST MUST make sure that all operations on
the connection list are done *atomically*.
This is achieved via semaphores.
Typically, you use CreateSemaphore(), and WaitForSingleObject()
to do atomic operations.
Anyway, hope this was of some assistance. I strongly recommend
getting the book. It goes over all the major server designs.
Josh