ProudNet provides a simple API module that can register a game server in Windows service.
Windows service is a process that conducts specific functions and is operated for a long time. Windows service is operated when Microsoft Windows operating system is booted up and it can be operated even if a user does not log on. And as long as Windows is operated, it is operated at a background mode. This is similar with the concept of Unix daemon.
1. Overview
- NTService.exe [-install | -uninstall]
2. Option
- Options such as -install and -uninstall are for registration & termination of Windows service.
3. Execution Screen
A Sample Program registered at Windows Service
4. Example code of making registration module
#include "stdafx.h"
#include "../../include/ProudNetServer.h"
#include "../../include/NTService.h"
#include "conio.h"
using namespace Proud;
using namespace std;
int g_ServerPort = 33334;
{
public:
virtual void Log(int type, LPCWSTR text)
{
_tprintf(L"%s\n", text);
}
virtual void Pause()
{
printf("pause");
}
virtual void Stop()
{
printf("stop");
}
virtual void Continue()
{
printf("continue");
}
virtual void Run()
{
bool result = srv->
Start(p1, err);
if (result == false)
{
delete srv;
return;
}
puts("Game Server started.\n");
while (1)
{
Sleep(100);
if (_kbhit())
{
int ch = _getch();
switch (ch)
{
case 27:
return;
}
}
MSG msg;
MsgWaitForMultipleObjects(0, 0, TRUE, 100, QS_ALLEVENTS);
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!GetMessage(&msg, NULL, NULL, NULL))
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
}
CMySvrEvent g_svrEvent;
int wmain(int argc, WCHAR* argv[], WCHAR* envp[])
{
int nRetCode = 0;
return nRetCode;
}
- Please refer to <Installation Folder>/Sample/NTService for Windows source files related to this example.
5. Utilization of NTService