1 |
hedin |
3 |
#include "StdAfx.h"
|
2 |
|
|
#include ".\tcpserverclass.h"
|
3 |
|
|
|
4 |
|
|
TcpServerClass::TcpServerClass(void)
|
5 |
|
|
{
|
6 |
|
|
}
|
7 |
|
|
|
8 |
|
|
TcpServerClass::~TcpServerClass(void)
|
9 |
|
|
{
|
10 |
|
|
}
|
11 |
|
|
|
12 |
|
|
void TcpServerClass::OnAccept(int nErrorCode)
|
13 |
|
|
{
|
14 |
hedin |
33 |
typedef std::list<TcpClientClass*>::iterator ClientIt;
|
15 |
|
|
|
16 |
hedin |
36 |
CString clientStr;
|
17 |
|
|
CString host;
|
18 |
|
|
unsigned int port;
|
19 |
|
|
|
20 |
hedin |
33 |
TcpClientClass* client = new TcpClientClass;
|
21 |
|
|
Accept(*client);
|
22 |
hedin |
3 |
CSocket::OnAccept(nErrorCode);
|
23 |
hedin |
33 |
|
24 |
|
|
mClients.push_back(client);
|
25 |
|
|
|
26 |
hedin |
36 |
|
27 |
|
|
client->GetPeerName(host,port);
|
28 |
|
|
clientStr.Format("Connection from %s:%d\n", host,port);
|
29 |
|
|
OutputDebugString(clientStr);
|
30 |
|
|
|
31 |
hedin |
33 |
for (ClientIt it = mClients.begin(); it != mClients.end(); it++)
|
32 |
|
|
{
|
33 |
|
|
if ( (*it)->isClosed )
|
34 |
|
|
{
|
35 |
|
|
delete (*it);
|
36 |
|
|
mClients.erase(it);
|
37 |
|
|
//efter erase er iteratoren ikke længere valid
|
38 |
|
|
it = mClients.begin();
|
39 |
|
|
}
|
40 |
|
|
}
|
41 |
|
|
|
42 |
hedin |
3 |
}
|