1 |
#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 |
typedef std::list<TcpClientClass*>::iterator ClientIt;
|
15 |
|
16 |
CString clientStr;
|
17 |
CString host;
|
18 |
unsigned int port;
|
19 |
|
20 |
TcpClientClass* client = new TcpClientClass;
|
21 |
Accept(*client);
|
22 |
CSocket::OnAccept(nErrorCode);
|
23 |
|
24 |
mClients.push_back(client);
|
25 |
|
26 |
|
27 |
client->GetPeerName(host,port);
|
28 |
clientStr.Format("Connection from %s:%d\n", host,port);
|
29 |
OutputDebugString(clientStr);
|
30 |
|
31 |
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 |
}
|