Danbias/Code/Network/OysterNetworkServer/ServerMain.cpp

112 lines
2.2 KiB
C++
Raw Normal View History

2013-11-18 16:47:57 +01:00
#include <iostream>
#include <WinSock2.h>
#include <vector>
2013-11-22 14:23:08 +01:00
#include <vld.h>
#include "../NetworkDependencies/WinsockFunctions.h"
#include "../NetworkDependencies/Listener.h"
#include "../NetworkDependencies/Translator.h"
2013-12-03 13:08:04 +01:00
#include "../NetworkDependencies/ThreadedClient.h"
#include "../NetworkDependencies/OysterByte.h"
#include "../NetworkDependencies/PostBox.h"
#include "../../Misc/WinTimer.h"
#include "../../Misc/Utilities.h"
#include "../../Misc/Utilities-Impl.h"
2013-11-18 16:47:57 +01:00
#include "TestClass.h"
#include "IServer.h"
2013-12-08 23:56:17 +01:00
#include "IClient.h"
#pragma comment(lib, "ws2_32.lib")
using namespace std;
using namespace Oyster::Network::Server;
2013-11-21 14:49:30 +01:00
using namespace Oyster::Network;
using namespace ::Protocols;
using namespace Utility;
using namespace ::Utility::DynamicMemory;
2013-12-08 23:56:17 +01:00
void clientProc(IClient* client);
int main()
{
Test tests;
SmartPointer<OysterByte> sendBuffer = new OysterByte;
2013-12-08 23:56:17 +01:00
SmartPointer<OysterByte> recvBuffer = new OysterByte;
ProtocolSet* set = new ProtocolSet;
2013-11-21 14:49:30 +01:00
cout << "Server" << endl;
2013-11-22 08:56:00 +01:00
Translator t;
int errorCode = 0;
2013-11-19 14:21:25 +01:00
2013-11-26 13:45:03 +01:00
if(!InitWinSock())
{
2013-11-26 13:45:03 +01:00
cout << "errorMessage: unable to start winsock" << endl;
}
2013-12-08 23:56:17 +01:00
IServer server;
IServer::INIT_DESC initDesc;
initDesc.port = 9876;
initDesc.proc = clientProc;
server.Init(initDesc);
server.Start();
Sleep(1000);
//Create a test protocol
ProtocolPlayerPos test;
test.clientID = 0;
test.ID = 5;
test.nrOfFloats = 10;
test.matrix = new float[test.nrOfFloats];
for(int i = 0; i < (int)test.nrOfFloats; i++)
{
test.matrix[i] = (float)i;
}
t.Pack(test, sendBuffer);
WinTimer timer;
while(1)
{
//Fetch new clients from the postbox
/*
//Send a message every 1 seconds to all clients.
if(timer.getElapsedSeconds() > 1)
{
cout << "Sending to " << clients.size() << " clients." << endl;
timer.reset();
for(int i = 0; i < (int)clients.size(); i++)
{
clients.at(i)->Send(sendBuffer);
}
}*/
/*//Fetch messages
if(recvPostBox->FetchMessage(recvBuffer))
{
t.Unpack(set, recvBuffer);
2013-12-08 23:56:17 +01:00
//PrintOutMessage(set);
set->Release();
}*/
Sleep(1);
}
server.Stop();
server.Shutdown();
//listener.Shutdown();
2013-12-04 14:58:15 +01:00
Sleep(1000);
system("pause");
2013-11-22 15:48:49 +01:00
return 0;
}
2013-12-08 23:56:17 +01:00
void clientProc(IClient* client)
{
cout << "Proc" << endl;
clients.push_back(client);
}