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 09:17:07 +01:00
|
|
|
#include "..\NetworkDependencies\Translator.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-11-25 20:27:23 +01:00
|
|
|
#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;
|
2013-11-27 11:01:22 +01:00
|
|
|
using namespace Oyster::Network::Protocols;
|
2013-11-21 13:40:52 +01:00
|
|
|
using namespace Oyster::Network::Client;
|
2013-11-19 13:42:50 +01:00
|
|
|
|
2013-11-22 14:23:08 +01:00
|
|
|
void chat(Client &client);
|
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
|
|
|
|
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
|
|
|
|
2013-11-28 16:20:50 +01:00
|
|
|
chat(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-11-22 14:23:08 +01:00
|
|
|
void chat(Client &client)
|
2013-11-19 14:18:34 +01:00
|
|
|
{
|
2013-11-22 09:17:07 +01:00
|
|
|
Oyster::Network::Translator *t = new Oyster::Network::Translator();
|
|
|
|
|
2013-11-27 11:01:22 +01:00
|
|
|
Oyster::Network::OysterByte msgRecv;
|
2013-11-22 09:17:07 +01:00
|
|
|
string msgSend = "";
|
|
|
|
|
2013-11-22 11:40:55 +01:00
|
|
|
ProtocolSet* set = new ProtocolSet;
|
2013-11-22 09:17:07 +01:00
|
|
|
ProtocolTest test;
|
2013-11-25 19:00:33 +01:00
|
|
|
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++;
|
|
|
|
}
|
2013-11-19 14:18:34 +01:00
|
|
|
|
|
|
|
bool chatDone = false;
|
|
|
|
|
|
|
|
while(!chatDone)
|
|
|
|
{
|
|
|
|
client.Recv(msgRecv);
|
2013-11-22 09:17:07 +01:00
|
|
|
|
2013-11-25 19:00:33 +01:00
|
|
|
t->Unpack(set, msgRecv);
|
2013-11-22 14:23:08 +01:00
|
|
|
|
2013-11-25 19:00:33 +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:
|
2013-11-22 11:40:55 +01:00
|
|
|
cout <<"Client 2: " << set->Protocol.pTest->textMessage <<endl;
|
2013-11-25 19:00:33 +01:00
|
|
|
for(int i = 0; i < set->Protocol.pTest->numOfFloats; i++)
|
|
|
|
{
|
2013-11-27 11:01:22 +01:00
|
|
|
cout << set->Protocol.pTest->f[i] << ' ' ;
|
2013-11-25 19:00:33 +01:00
|
|
|
}
|
2013-11-25 20:27:23 +01:00
|
|
|
cout << endl;
|
2013-11-22 09:17:07 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-11-22 14:23:08 +01:00
|
|
|
|
|
|
|
set->Release();
|
2013-11-27 11:01:22 +01:00
|
|
|
msgRecv.Clear(1000);
|
2013-11-19 14:18:34 +01:00
|
|
|
|
2013-11-28 16:15:28 +01:00
|
|
|
/*std::getline(std::cin, msgSend);
|
2013-11-25 19:00:33 +01:00
|
|
|
|
|
|
|
|
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-20 10:33:52 +01:00
|
|
|
}
|
2013-11-22 09:17:07 +01:00
|
|
|
|
|
|
|
test.textMessage = msgSend;
|
|
|
|
|
2013-11-27 11:01:22 +01:00
|
|
|
t->Pack(test, msgRecv);
|
2013-11-22 09:17:07 +01:00
|
|
|
|
2013-11-27 11:01:22 +01:00
|
|
|
client.Send(msgRecv);
|
2013-11-19 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
chatDone = true;
|
|
|
|
}
|
|
|
|
|
2013-11-28 16:15:28 +01:00
|
|
|
cin.clear();*/
|
2013-11-19 14:59:00 +01:00
|
|
|
|
2013-11-19 14:18:34 +01:00
|
|
|
}
|
|
|
|
|
2013-11-22 14:23:08 +01:00
|
|
|
delete t;
|
2013-11-22 11:40:55 +01:00
|
|
|
delete set;
|
2013-11-18 16:34:50 +01:00
|
|
|
}
|