Danbias/Code/Network/OysterNetworkServer/ServerMain.cpp

61 lines
1020 B
C++
Raw Normal View History

2013-11-18 16:47:57 +01:00
#include <iostream>
#include <vector>
2013-11-22 14:23:08 +01:00
#include <vld.h>
2013-12-17 08:45:47 +01:00
#include <mutex>
#include "../NetworkDependencies/WinsockFunctions.h"
2013-12-16 08:59:38 +01:00
#include "../NetworkAPI/NetworkServer.h"
#include "../NetworkAPI/CustomNetProtocol.h"
#include "../NetworkAPI/NetworkCallbackHelper.h"
2013-12-16 08:59:38 +01:00
using namespace Oyster::Network;
using namespace std;
2013-12-17 08:45:47 +01:00
std::mutex m;
vector<NetworkClient> clients;
2013-12-17 08:45:47 +01:00
2013-12-16 08:59:38 +01:00
void proc(NetworkClient client)
{
cout << "Hej" << endl;
2013-12-17 08:45:47 +01:00
m.lock();
clients.push_back(client);
m.unlock();
2013-12-16 08:59:38 +01:00
}
int main()
{
2013-12-16 11:04:00 +01:00
SetDllDirectory("..\\DLL\\");
2013-12-16 08:59:38 +01:00
NetworkServer server;
Oyster::Network::NetworkServer::INIT_DESC desc;
desc.port = 15151;
desc.callbackType = NetworkClientCallbackType_Function;
//desc.recvObj = proc;
2013-12-16 08:59:38 +01:00
if(!server.Init(desc))
{
cout << "Init failed" << endl;
return 0;
}
if(!server.Start())
{
2013-12-16 08:59:38 +01:00
cout << "Start failed" << endl;
return 0;
}
2013-12-16 08:59:38 +01:00
cout << "Server started" << endl;
while(1)
{
2013-12-17 08:45:47 +01:00
Sleep(1000);
m.lock();
cout << clients.size() << endl;
m.unlock();
2013-12-16 08:59:38 +01:00
}
2013-12-17 08:45:47 +01:00
server.Stop();
2013-12-16 08:59:38 +01:00
system("pause");
2013-11-22 15:48:49 +01:00
return 0;
}