it's quite easy actually
Save the incoming connections in an array.
start a new thread that gets the data from the socket and put it in an output buffer (make sure it's threadsafe) and that's it
edit 18-6-2014
here is a c++ example from my network class it is not perfect but you will get the idea
m_clientList is a vector in which I save the connections but I don't know if c# has a vector something like a list will work to
DWORD WINAPI Network::ServerAcceptConnections(LPVOID lpParam)
{
Network* network = (Network*) lpParam;
SOCKET new_socket;
char *message;
int c = sizeof(struct sockaddr_in);
DWORD dwWaitResult;
Sleep(100);
while (true)
{
new_socket = accept(pNetwork->m_s , (struct sockaddr *)&pNetwork->m_client, &c);
if (new_socket != INVALID_SOCKET )
{
dwWaitResult = WaitForSingleObject(
pNetwork->m_ClientListMutex, // handle to mutex
INFINITE); // no time-out interval
if (dwWaitResult == WAIT_OBJECT_0)
{
__try
{
//Reply to the client
if (network->m_clientList.size() < network->m_maxConnections)
{
if(network->m_debugModus) print("DEBUG MODUS: Connection accepted\r\n");
network->m_clientList.push_back(new_socket);
message = NETWORK_CLASS_CONNECTION_SUCCES;
Message out;
out.client = new_socket;
out.message = message;
out.size = strlen(message);
pNetwork->SendData(out);
}
else
{
if(pNetwork->m_debugModus) printf("DEBUG MODUS: Max connections reached\r\n");
message = NETWORK_CLASS_MAX_CONNECTIONS;
pNetwork->Send(new_socket, message, strlen(message));
closesocket(new_socket);
}
}
__finally {
// Release ownership of the mutex object
if (! ReleaseMutex(network->m_ClientListMutex))
{
if(pNetwork->m_debugModus) printf("DEBUG MODUS: AcceptConnections: Cant Relese the Mutex\r\n");
}
}
}
else if (dwWaitResult == WAIT_ABANDONED)
{
if(network->m_debugModus) print("DEBUG MODUS: SendDataThread: The thread got ownership of an abandoned mutex\r\n");
return FALSE;
}
}
else
{
if(pNetwork->m_debugModus) printf("DEBUG MODUS: accept failed with error code : %d\r\n" , WSAGetLastError());
}
}
return TRUE;
}