www.pudn.com > ChatUseIOCP.rar > ChatServer.cpp
// ChatServer.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "ChatServerSocket.h"
int _tmain(int argc, _TCHAR* argv[])
{
CChatServerSocket server;
HANDLE hDieEvent;
// Create event that well use to disconnect
hDieEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
server.WriteLog(Datatal::LP_LOW, DTSERVERID, "misc", "Starting the server...");
// Start our server. Port 4321, start with 5 clients, maximum of 400 clients.
server.StartServer(4320, 500, 2000);
// Wait for our dieevent
bool bCanRun = true;
DWORD dwRes = 0;
while (bCanRun)
{
dwRes = WaitForSingleObject(hDieEvent, 10000);
switch (dwRes)
{
case WAIT_OBJECT_0:
bCanRun = false;
break;
case WAIT_TIMEOUT:
server.Maintenance(); //Do a little maintenance...
break;
//default:
//bCanRun = false;
}
// You should read input or something and trigger die event...
}
server.StopServer();
CloseHandle(hDieEvent);
return 0;
}