From 23a05bf431887a4fb4d1e1fadf51c99ae6c801ed Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 17 Dec 2013 08:45:47 +0100 Subject: [PATCH 1/4] Network - OysterByte += operator --- .../NetworkDependencies/OysterByte.cpp | 19 +++++++++++++++++++ Code/Network/NetworkDependencies/OysterByte.h | 2 ++ .../OysterNetworkClient/ClientMain.cpp | 12 +++++++++++- .../OysterNetworkServer/ServerMain.cpp | 14 +++++++++++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Code/Network/NetworkDependencies/OysterByte.cpp b/Code/Network/NetworkDependencies/OysterByte.cpp index 99c88d44..ec87a5f6 100644 --- a/Code/Network/NetworkDependencies/OysterByte.cpp +++ b/Code/Network/NetworkDependencies/OysterByte.cpp @@ -109,6 +109,25 @@ OysterByte::operator unsigned char*() return byteArray; } +OysterByte& OysterByte::operator +=(const OysterByte& obj) +{ + int newSize = this->size + obj.size; + + if(newSize >= (int)capacity) + { + IncreaseCapacity(this->size); + } + + for(int i = size, j = 0; i < newSize; i++, j++) + { + this->byteArray[i] = obj.byteArray[j]; + } + + this->size = newSize; + + return *this; +} + ///////////// // Private // ///////////// diff --git a/Code/Network/NetworkDependencies/OysterByte.h b/Code/Network/NetworkDependencies/OysterByte.h index e525095b..4f6f4557 100644 --- a/Code/Network/NetworkDependencies/OysterByte.h +++ b/Code/Network/NetworkDependencies/OysterByte.h @@ -40,6 +40,8 @@ namespace Oyster operator const char*(); operator unsigned char*(); + OysterByte& operator +=(const OysterByte& obj); + private: //Expands the byteArray void IncreaseCapacity(unsigned int cap); diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index a04294c6..2d008356 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -41,11 +41,21 @@ int main() } //client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); + OysterByte bytes, bytes2, bytes3; + bytes.AddSize(4); + bytes2.AddSize(5); + strcpy_s(bytes, 5, "asda"); + strcpy_s(bytes2, 6, "asdab"); + bytes += bytes2; + bytes += bytes; + bytes += bytes; + bytes3 = bytes; + cout << "Done" << endl; while(1) { - + } ShutdownWinSock(); diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 1ad3c725..48e36e8e 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -1,15 +1,22 @@ #include #include #include +#include #include "../NetworkDependencies/WinsockFunctions.h" #include "../NetworkAPI/NetworkServer.h" using namespace Oyster::Network; using namespace std; +vector clients; +std::mutex m; + void proc(NetworkClient client) { cout << "Hej" << endl; + m.lock(); + clients.push_back(client); + m.unlock(); } int main() @@ -38,9 +45,14 @@ int main() while(1) { - + Sleep(1000); + m.lock(); + cout << clients.size() << endl; + m.unlock(); + break; } + server.Stop(); system("pause"); From f31da908305c33e25994b4bc8e06503fb9bd638f Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 17 Dec 2013 09:05:32 +0100 Subject: [PATCH 2/4] Network - Connection set blocking to true while connecting. --- Code/Network/NetworkAPI/NetworkClient.cpp | 6 +++--- Code/Network/OysterNetworkClient/ClientMain.cpp | 2 +- Code/Network/OysterNetworkServer/ServerMain.cpp | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 9fa033f1..12d14144 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -48,8 +48,8 @@ struct ClientDataContainer InitWinSock(); callbackType = NetworkProtocolCallbackType_Unknown; sendPostBox = new PostBox(); - connection.SetBlockingMode(false); connection.InitiateClient(); + connection.SetBlockingMode(false); } ClientDataContainer(IThreadObject* o, unsigned int socket ) :connection(socket), ID(currID++) @@ -204,17 +204,17 @@ NetworkClient::~NetworkClient() bool NetworkClient::Connect(unsigned short port, const char serverIP[]) { + privateData->data->connection.SetBlockingMode(true); int result = this->privateData->data->connection.Connect(port, serverIP); //Connect has succeeded if(result == 0) { privateData->data->thread.Start(); + privateData->data->connection.SetBlockingMode(false); return true; } - privateData->data->connection.SetBlockingMode(false); - //Connect has failed return false; } diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index 2d008356..b4eb91d7 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -31,7 +31,7 @@ int main() //Connect to server //errorCode = client->Connect(15151, "193.11.186.101"); - errorCode = client.Connect(15151, "127.0.0.1"); + errorCode = client.Connect(15151, "193.11.187.62"); client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); if(errorCode != 1) diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 48e36e8e..4f74cef9 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -4,12 +4,14 @@ #include #include "../NetworkDependencies/WinsockFunctions.h" #include "../NetworkAPI/NetworkServer.h" +#include "../NetworkAPI/CustomNetProtocol.h" +#include "../NetworkAPI/NetworkCallbackHelper.h" using namespace Oyster::Network; using namespace std; -vector clients; std::mutex m; +vector clients; void proc(NetworkClient client) { From cbf3c7db8f1ded707fc7c0251f06d2dc75d834e9 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 17 Dec 2013 09:05:49 +0100 Subject: [PATCH 3/4] asd --- Code/Network/OysterNetworkServer/ServerMain.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 4f74cef9..eb66154a 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -51,7 +51,6 @@ int main() m.lock(); cout << clients.size() << endl; m.unlock(); - break; } server.Stop(); From 7c029a5242697deb5807fb281b4f31334eca8d5c Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 17 Dec 2013 10:58:07 +0100 Subject: [PATCH 4/4] Network - Fixed bugs --- Code/Network/NetworkAPI/CustomNetProtocol.cpp | 1 - Code/Network/NetworkAPI/Translator.cpp | 1 + Code/Network/NetworkDependencies/OysterByte.cpp | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.cpp b/Code/Network/NetworkAPI/CustomNetProtocol.cpp index 1933d907..91fb7267 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.cpp +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -32,7 +32,6 @@ struct CustomNetProtocol::PrivateData attributes[i->first] = i->second; } } - attributes = o.attributes; } ~PrivateData() { diff --git a/Code/Network/NetworkAPI/Translator.cpp b/Code/Network/NetworkAPI/Translator.cpp index 75598b75..e321f31e 100644 --- a/Code/Network/NetworkAPI/Translator.cpp +++ b/Code/Network/NetworkAPI/Translator.cpp @@ -35,6 +35,7 @@ struct Translator::PrivateData auto end = ((MyCastingStruct*)protocol.privateData)->attributes.end(); size = 4; //size(int) + message.SetSize(0); message.PackInt(size, bytes); //Find all the data types diff --git a/Code/Network/NetworkDependencies/OysterByte.cpp b/Code/Network/NetworkDependencies/OysterByte.cpp index ec87a5f6..7cbbde58 100644 --- a/Code/Network/NetworkDependencies/OysterByte.cpp +++ b/Code/Network/NetworkDependencies/OysterByte.cpp @@ -44,6 +44,7 @@ void OysterByte::Resize(unsigned int cap) { delete[] byteArray; byteArray = new unsigned char[cap]; + capacity = cap; } }