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/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index e5f910e8..69b22380 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,6 +204,7 @@ 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 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 99c88d44..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; } } @@ -109,6 +110,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/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 1ad3c725..eb66154a 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -1,15 +1,24 @@ #include #include #include +#include #include "../NetworkDependencies/WinsockFunctions.h" #include "../NetworkAPI/NetworkServer.h" +#include "../NetworkAPI/CustomNetProtocol.h" +#include "../NetworkAPI/NetworkCallbackHelper.h" using namespace Oyster::Network; using namespace std; +std::mutex m; +vector clients; + void proc(NetworkClient client) { cout << "Hej" << endl; + m.lock(); + clients.push_back(client); + m.unlock(); } int main() @@ -38,9 +47,13 @@ int main() while(1) { - + Sleep(1000); + m.lock(); + cout << clients.size() << endl; + m.unlock(); } + server.Stop(); system("pause");