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