2013-11-18 16:47:57 +01:00
|
|
|
#include <iostream>
|
2013-11-19 13:42:50 +01:00
|
|
|
#include <WinSock2.h>
|
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-22 14:23:08 +01:00
|
|
|
#include "..\NetworkDependencies\Protocols.h"
|
2013-11-27 11:01:22 +01:00
|
|
|
#include "../NetworkDependencies/OysterByte.h"
|
2013-11-28 16:14:42 +01:00
|
|
|
#include "../../Misc/ThreadSafeQueue.h"
|
2013-12-03 13:08:04 +01:00
|
|
|
#include "../NetworkDependencies/ThreadedClient.h"
|
2013-12-03 23:12:48 +01:00
|
|
|
#include "../../Misc/WinTimer.h"
|
|
|
|
#include "../../Misc/Utilities.h"
|
2013-11-25 20:27:23 +01:00
|
|
|
|
|
|
|
#pragma comment(lib, "ws2_32.lib")
|
2013-11-22 09:17:07 +01:00
|
|
|
|
2013-11-18 16:47:57 +01:00
|
|
|
using namespace std;
|
2013-11-27 11:01:22 +01:00
|
|
|
using namespace Oyster::Network::Protocols;
|
2013-12-03 13:08:04 +01:00
|
|
|
using namespace Oyster::Network;
|
2013-12-03 23:12:48 +01:00
|
|
|
using namespace Utility;
|
2013-12-04 12:40:49 +01:00
|
|
|
using namespace Utility::DynamicMemory;
|
2013-11-19 13:42:50 +01:00
|
|
|
|
2013-12-03 13:08:04 +01:00
|
|
|
void chat(ThreadedClient &client);
|
2013-12-03 23:12:48 +01:00
|
|
|
void PrintOutMessage(ProtocolSet* set);
|
2013-11-22 08:56:00 +01:00
|
|
|
|
2013-11-18 16:34:50 +01:00
|
|
|
int main()
|
|
|
|
{
|
2013-11-26 13:45:03 +01:00
|
|
|
int errorCode;
|
|
|
|
|
2013-11-19 13:42:50 +01:00
|
|
|
char msgRecv[255] = "\0";
|
|
|
|
|
2013-11-26 13:45:03 +01:00
|
|
|
InitWinSock();
|
2013-11-19 13:42:50 +01:00
|
|
|
|
2013-11-19 09:34:24 +01:00
|
|
|
cout << "Client" << endl;
|
2013-11-18 16:47:57 +01:00
|
|
|
|
2013-11-19 13:42:50 +01:00
|
|
|
//Create Client
|
2013-12-03 23:12:48 +01:00
|
|
|
ThreadedClient* client = new ThreadedClient;
|
2013-11-19 13:42:50 +01:00
|
|
|
|
|
|
|
//Connect to server
|
2013-12-12 10:32:43 +01:00
|
|
|
errorCode = client->Connect(15151, "193.11.186.101");
|
2013-11-26 13:45:03 +01:00
|
|
|
|
|
|
|
if(errorCode != 0)
|
|
|
|
{
|
|
|
|
wstring errorTest = GetErrorMessage(errorCode);
|
|
|
|
wcout << "errorMessage: " << errorTest << endl;
|
|
|
|
}
|
2013-11-22 08:56:00 +01:00
|
|
|
|
2013-12-03 23:12:48 +01:00
|
|
|
chat(*client);
|
2013-12-11 21:45:43 +01:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-03 23:12:48 +01:00
|
|
|
delete client;
|
2013-11-19 13:42:50 +01:00
|
|
|
|
2013-11-26 13:45:03 +01:00
|
|
|
ShutdownWinSock();
|
2013-11-19 13:42:50 +01:00
|
|
|
|
|
|
|
system("pause");
|
2013-11-18 16:34:50 +01:00
|
|
|
return 0;
|
2013-11-19 13:42:50 +01:00
|
|
|
}
|
|
|
|
|
2013-12-03 13:08:04 +01:00
|
|
|
void chat(ThreadedClient &client)
|
2013-11-19 14:18:34 +01:00
|
|
|
{
|
2013-12-11 21:45:43 +01:00
|
|
|
/*Oyster::Network::Translator *t = new Oyster::Network::Translator();
|
2013-12-04 12:40:49 +01:00
|
|
|
IPostBox< SmartPointer<OysterByte >> *postBox = new PostBox< SmartPointer<OysterByte >>;
|
2013-11-22 09:17:07 +01:00
|
|
|
|
2013-12-11 21:45:43 +01:00
|
|
|
//client.setRecvPostBox(postBox);
|
2013-12-03 23:12:48 +01:00
|
|
|
|
2013-12-06 10:45:53 +01:00
|
|
|
SmartPointer<OysterByte> msgRecv = new OysterByte();
|
|
|
|
SmartPointer<OysterByte> msgSend = new OysterByte();
|
2013-11-22 09:17:07 +01:00
|
|
|
|
2013-11-22 11:40:55 +01:00
|
|
|
ProtocolSet* set = new ProtocolSet;
|
2013-12-03 11:46:46 +01:00
|
|
|
ProtocolPlayerPos test;
|
|
|
|
test.ID = 5;
|
2013-12-03 23:12:48 +01:00
|
|
|
test.nrOfFloats = 5;
|
|
|
|
test.matrix = new float[test.nrOfFloats];
|
2013-12-03 11:46:46 +01:00
|
|
|
float temp = 10;
|
2013-12-03 23:12:48 +01:00
|
|
|
for(int i = 0; i < (int)test.nrOfFloats; i++)
|
2013-11-25 19:00:33 +01:00
|
|
|
{
|
2013-12-03 11:46:46 +01:00
|
|
|
test.matrix[i] = temp;
|
2013-11-25 19:00:33 +01:00
|
|
|
temp++;
|
|
|
|
}
|
2013-12-04 12:40:49 +01:00
|
|
|
t->Pack(test, msgSend);
|
2013-12-03 23:12:48 +01:00
|
|
|
|
|
|
|
WinTimer timer;
|
2013-11-19 14:18:34 +01:00
|
|
|
|
2013-12-03 23:12:48 +01:00
|
|
|
while(1)
|
2013-11-19 14:18:34 +01:00
|
|
|
{
|
2013-12-03 23:12:48 +01:00
|
|
|
//Fetch new messages from the postbox
|
2013-12-11 21:45:43 +01:00
|
|
|
//if(postBox->FetchMessage(msgRecv))
|
2013-11-22 09:17:07 +01:00
|
|
|
{
|
2013-12-04 12:40:49 +01:00
|
|
|
t->Unpack(set, msgRecv);
|
2013-11-25 19:00:33 +01:00
|
|
|
|
2013-12-08 23:56:17 +01:00
|
|
|
//PrintOutMessage(set);
|
2013-12-03 23:12:48 +01:00
|
|
|
set->Release();
|
|
|
|
}
|
2013-11-25 19:00:33 +01:00
|
|
|
|
2013-12-03 23:12:48 +01:00
|
|
|
//Send message to server each second
|
|
|
|
if(timer.getElapsedSeconds() > 1)
|
2013-11-22 09:17:07 +01:00
|
|
|
{
|
2013-12-03 23:12:48 +01:00
|
|
|
cout << "Sending to server." << endl;
|
|
|
|
timer.reset();
|
2013-12-11 21:45:43 +01:00
|
|
|
//client.Send(msgSend);
|
2013-12-03 23:12:48 +01:00
|
|
|
}
|
2013-12-09 10:48:43 +01:00
|
|
|
Sleep(1);
|
2013-12-03 23:12:48 +01:00
|
|
|
}
|
2013-11-22 09:17:07 +01:00
|
|
|
|
2013-12-03 23:12:48 +01:00
|
|
|
delete postBox;
|
|
|
|
delete t;
|
2013-12-11 21:45:43 +01:00
|
|
|
delete set;*/
|
2013-12-03 23:12:48 +01:00
|
|
|
}
|
2013-11-22 09:17:07 +01:00
|
|
|
|
2013-12-03 23:12:48 +01:00
|
|
|
void PrintOutMessage(ProtocolSet* set)
|
|
|
|
{
|
|
|
|
switch(set->type)
|
|
|
|
{
|
|
|
|
case PackageType_header:
|
|
|
|
break;
|
|
|
|
case PackageType_test:
|
|
|
|
cout <<"Client 2: " << set->Protocol.pTest->textMessage <<endl;
|
|
|
|
for(int i = 0; i < (int)set->Protocol.pTest->numOfFloats; i++)
|
|
|
|
{
|
|
|
|
cout << set->Protocol.pTest->f[i] << ' ' ;
|
2013-11-19 14:18:34 +01:00
|
|
|
}
|
2013-12-03 23:12:48 +01:00
|
|
|
cout << endl;
|
|
|
|
break;
|
2013-11-19 14:18:34 +01:00
|
|
|
|
2013-12-03 23:12:48 +01:00
|
|
|
case PackageType_player_pos:
|
|
|
|
cout << "ID " << set->Protocol.pPlayerPos->ID << endl;
|
|
|
|
for(int i = 0; i < (int)set->Protocol.pPlayerPos->nrOfFloats; i++)
|
2013-11-19 14:18:34 +01:00
|
|
|
{
|
2013-12-03 23:12:48 +01:00
|
|
|
cout << set->Protocol.pPlayerPos->matrix[i] << ' ';
|
2013-11-19 14:18:34 +01:00
|
|
|
}
|
2013-12-03 23:12:48 +01:00
|
|
|
cout << endl;
|
|
|
|
break;
|
2013-11-19 14:18:34 +01:00
|
|
|
}
|
2013-11-18 16:34:50 +01:00
|
|
|
}
|