Danbias/Code/Network/OysterNetworkClient/ClientMain.cpp

175 lines
3.0 KiB
C++
Raw Normal View History

2013-11-18 16:47:57 +01:00
#include <iostream>
#include <WinSock2.h>
2013-11-22 14:23:08 +01:00
#include <vld.h>
#include "../NetworkDependencies/WinsockFunctions.h"
2013-11-22 09:17:07 +01:00
#include "..\NetworkDependencies\Translator.h"
2013-11-22 14:23:08 +01:00
#include "..\NetworkDependencies\Protocols.h"
#include "../NetworkDependencies/OysterByte.h"
#include "../../Misc/ThreadSafeQueue.h"
#include "Client.h"
#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;
using namespace Oyster::Network::Protocols;
using namespace Oyster::Network::Client;
2013-11-22 14:23:08 +01:00
void chat(Client &client);
2013-11-22 08:56:00 +01:00
int main()
{
2013-11-26 13:45:03 +01:00
int errorCode;
char msgRecv[255] = "\0";
2013-11-26 13:45:03 +01:00
InitWinSock();
cout << "Client" << endl;
2013-11-18 16:47:57 +01:00
//Create Client
Client client;
//Connect to server
2013-11-26 13:45:03 +01:00
errorCode = client.Connect(9876, "localhost");
if(errorCode != 0)
{
wstring errorTest = GetErrorMessage(errorCode);
wcout << "errorMessage: " << errorTest << endl;
}
2013-11-22 08:56:00 +01:00
//test queue
//-----------------------------------------
Oyster::Queue::IQueue<int> *test = new Oyster::Queue::ThreadSafeQueue<int>();
Oyster::Queue::IQueue<int> *test2 = new Oyster::Queue::ThreadSafeQueue<int>();
for(int i = 0; i < 100; i++)
{
//test->Push(i);
//cout << test->Pop() << endl;
}
cout << "heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeej" <<endl;
for(int i = 99; i > -1; i--)
{
//test->Push(i);
//cout << test->Pop() << endl;
}
if(test->IsEmpty())
{
for(int i = 99; i > -1; i--)
{
test->Push(i);
//cout << test->Pop() << endl;
}
}
for(int i = 0; i < 50; i++)
{
test2->Push(i);
}
//test2->Swap(*test);
cout << "TEST 1-50" <<endl;
int size = test->Size();
for(int i = 0; i < size; i++)
{
//cout << test->Pop() << endl;
}
cout << "TEST2 99-1" <<endl;
size = test2->Size();
for(int i = 0; i < size; i++)
{
//cout << test2->Pop() << endl;
}
cout << test->Front() << " " << test2->Front() <<endl;
delete test;
delete test2;
//chat(client);
2013-11-26 13:45:03 +01:00
ShutdownWinSock();
system("pause");
return 0;
}
2013-11-22 14:23:08 +01:00
void chat(Client &client)
{
2013-11-22 09:17:07 +01:00
Oyster::Network::Translator *t = new Oyster::Network::Translator();
Oyster::Network::OysterByte msgRecv;
2013-11-22 09:17:07 +01:00
string msgSend = "";
ProtocolSet* set = new ProtocolSet;
2013-11-22 09:17:07 +01:00
ProtocolTest test;
test.numOfFloats = 5;
test.f = new float[test.numOfFloats];
float temp = 12345.5654f;
for(int i = 0; i < 5; i++)
{
test.f[i] = temp;
temp++;
}
bool chatDone = false;
while(!chatDone)
{
client.Recv(msgRecv);
2013-11-22 09:17:07 +01:00
t->Unpack(set, msgRecv);
2013-11-22 14:23:08 +01:00
switch(set->type)
2013-11-22 09:17:07 +01:00
{
2013-11-28 08:51:21 +01:00
case PackageType_header:
2013-11-22 09:17:07 +01:00
break;
2013-11-28 08:51:21 +01:00
case PackageType_test:
cout <<"Client 2: " << set->Protocol.pTest->textMessage <<endl;
for(int i = 0; i < set->Protocol.pTest->numOfFloats; i++)
{
cout << set->Protocol.pTest->f[i] << ' ' ;
}
cout << endl;
2013-11-22 09:17:07 +01:00
break;
}
2013-11-22 14:23:08 +01:00
set->Release();
msgRecv.Clear(1000);
/*std::getline(std::cin, msgSend);
2013-11-22 14:23:08 +01:00
2013-11-22 09:17:07 +01:00
if( msgSend != "exit")
{
if(msgSend.length() < 1)
{
msgSend = "ERROR!";
}
2013-11-22 09:17:07 +01:00
test.textMessage = msgSend;
t->Pack(test, msgRecv);
2013-11-22 09:17:07 +01:00
client.Send(msgRecv);
}
else
{
chatDone = true;
}
cin.clear();*/
2013-11-19 14:59:00 +01:00
}
2013-11-22 14:23:08 +01:00
delete t;
delete set;
}