Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //class definition
- //class to handle all server side connections
- #include "server.h"
- //constructor
- HTNAPI::server::server()
- {
- canaccept = false;
- }
- //start server
- bool HTNAPI::server::start(int port)
- {
- server::port = port;
- const int iReqWinsockVer = 2; // Minimum winsock version required
- WSADATA wsaData;
- if (WSAStartup(MAKEWORD(iReqWinsockVer,0), &wsaData)==0)
- {
- // Check if major version is at least iReqWinsockVer
- if (LOBYTE(wsaData.wVersion) >= iReqWinsockVer)
- {
- /* ------- Call winsock functions here ------- */
- if(startacceptthread())
- {
- return true;
- }
- }
- else
- {
- // Required version not available
- }
- // Cleanup winsock
- if (WSACleanup()!=0)
- {
- // cleanup failed
- }
- }
- else
- {
- // startup failed
- }
- return false;
- }
- //start accept thread
- bool HTNAPI::server::startacceptthread()
- {
- canaccept = true;
- HANDLE acceptthreadhandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)HTNAPI::acceptthread, 0, 0, 0);
- //thread started
- if(acceptthreadhandle != NULL)
- {
- return true;
- }
- return false;
- }
- //stop accept thread
- void HTNAPI::server::stopacceptthread()
- {
- canaccept = false;
- }
- void HTNAPI::server::stop()
- {
- stopacceptthread();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement