From d78b48319d9a77506702f1a07a6b26640d7ffc5b Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 3 Dec 2013 11:46:46 +0100 Subject: [PATCH 01/17] Network - Added MessagePlayerPos Added MessagePlayerPos Fixed bugg with adding float array. --- .../Messages/MessageHeader.cpp | 1 - .../Messages/MessageHeader.h | 4 ++- .../Messages/MessagePlayerPos.cpp | 30 ++++++++++++++++ .../Messages/MessagePlayerPos.h | 34 +++++++++++++++++++ .../Messages/MessagesInclude.h | 1 + .../NetworkDependencies.vcxproj | 2 ++ .../NetworkDependencies.vcxproj.filters | 2 ++ Code/Network/NetworkDependencies/Packing.cpp | 8 ++--- Code/Network/NetworkDependencies/Protocols.h | 19 ++++++++++- .../NetworkDependencies/Translator.cpp | 10 ++++++ .../OysterNetworkClient/ClientMain.cpp | 20 +++++++---- .../OysterNetworkServer/ServerMain.cpp | 16 ++++----- 12 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 Code/Network/NetworkDependencies/Messages/MessagePlayerPos.cpp create mode 100644 Code/Network/NetworkDependencies/Messages/MessagePlayerPos.h diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp index 97acf526..36cc4c83 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp @@ -111,7 +111,6 @@ void MessageHeader::PackFloat(float i, OysterByte& bytes) void MessageHeader::PackFloat(float i[], unsigned int elementCount, OysterByte& bytes) { - bytes.AddSize(4); //Pack number of elements PackUnsignedInt(elementCount, bytes); diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.h b/Code/Network/NetworkDependencies/Messages/MessageHeader.h index 095ebc1e..61dfedab 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.h +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.h @@ -47,8 +47,9 @@ namespace Oyster void PackStr(char str[], OysterByte& bytes); void PackStr(std::string str, OysterByte& bytes); + //Maybe //TODO: Add Pack functions for Vec2, 3, 4 and maybe Matrix. Etc. - + //Unpack variables from message bool UnpackBool(OysterByte& bytes); @@ -71,6 +72,7 @@ namespace Oyster std::string UnpackStr(OysterByte& bytes); + //Maybe //TODO: Add Unpack functions for Vec2, 3, 4 and maybe Matrix. Etc. diff --git a/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.cpp b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.cpp new file mode 100644 index 00000000..673b586f --- /dev/null +++ b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.cpp @@ -0,0 +1,30 @@ +#include "MessagePlayerPos.h" + +using namespace Oyster::Network; +using namespace Oyster::Network::Messages; +using namespace Oyster::Network::Protocols; + +MessagePlayerPos::MessagePlayerPos() +{ +} + +MessagePlayerPos::~MessagePlayerPos() +{ +} + +void MessagePlayerPos::Pack(Protocols::ProtocolHeader& header, OysterByte& bytes) +{ + MessageHeader::Pack(header, bytes); + + PackInt(static_cast(&header)->ID, bytes); + PackFloat(static_cast(&header)->matrix, static_cast(&header)->nrOfFloats, bytes); + SetSize(bytes); +} + +void MessagePlayerPos::Unpack(OysterByte& bytes, Protocols::ProtocolHeader& header) +{ + MessageHeader::Unpack(bytes, header); + + static_cast(&header)->ID = UnpackInt(bytes); + static_cast(&header)->matrix = UnpackFloat(static_cast(&header)->nrOfFloats, bytes); +} \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.h b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.h new file mode 100644 index 00000000..247e200e --- /dev/null +++ b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.h @@ -0,0 +1,34 @@ +#ifndef NETWORK_DEPENDENCIES_MESSAGE_PLAYER_POS_H +#define NETWORK_DEPENDENCIES_MESSAGE_PLAYER_POS_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#include "MessageHeader.h" + +namespace Oyster +{ + namespace Network + { + namespace Messages + { + class MessagePlayerPos : public MessageHeader + { + public: + MessagePlayerPos(); + virtual ~MessagePlayerPos(); + + virtual void Pack(Protocols::ProtocolHeader& header, OysterByte& bytes); + virtual void Unpack(OysterByte& bytes, Protocols::ProtocolHeader& header); + + private: + + + + }; + } + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Messages/MessagesInclude.h b/Code/Network/NetworkDependencies/Messages/MessagesInclude.h index 8f4d41e3..8bdb5c8a 100644 --- a/Code/Network/NetworkDependencies/Messages/MessagesInclude.h +++ b/Code/Network/NetworkDependencies/Messages/MessagesInclude.h @@ -7,5 +7,6 @@ #include "MessageHeader.h" #include "MessageTest.h" +#include "MessagePlayerPos.h" #endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj index dfabbcba..129568cc 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj @@ -155,6 +155,7 @@ + @@ -168,6 +169,7 @@ + diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index 74cb9a56..e26441c6 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -10,6 +10,7 @@ + @@ -27,5 +28,6 @@ + \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Packing.cpp b/Code/Network/NetworkDependencies/Packing.cpp index 7adc395c..192700b6 100644 --- a/Code/Network/NetworkDependencies/Packing.cpp +++ b/Code/Network/NetworkDependencies/Packing.cpp @@ -87,7 +87,7 @@ namespace Oyster //floating point (32, 64-bit) void Pack(unsigned char buffer[], float i) { - int tempFloat = Pack754(i, 32, 8); + int tempFloat = (int)Pack754(i, 32, 8); Pack(buffer, tempFloat); } @@ -153,7 +153,7 @@ namespace Oyster fnorm = fnorm - 1.0; // calculate the binary form (non-float) of the significand data - significand = fnorm * ((1LL << significandbits) + 0.5f); + significand = (long long)(fnorm * ((1LL << significandbits) + 0.5f)); // get the biased exponent exp = shift + ((1 << (expbits - 1)) - 1); // shift + bias @@ -169,7 +169,7 @@ namespace Oyster //bool (1-bit) bool Unpackb(unsigned char buffer[]) { - return (bool)buffer; + return buffer; } //char (8-bit) @@ -305,7 +305,7 @@ namespace Oyster return 0.0; // pull the significand - result = (i&((1LL << significandbits) - 1)); // mask + result = (long double)(i&((1LL << significandbits) - 1)); // mask result /= (1LL << significandbits); // convert back to float result += 1.0f; // add the one back on diff --git a/Code/Network/NetworkDependencies/Protocols.h b/Code/Network/NetworkDependencies/Protocols.h index 8defcfb3..adf7154e 100644 --- a/Code/Network/NetworkDependencies/Protocols.h +++ b/Code/Network/NetworkDependencies/Protocols.h @@ -22,7 +22,7 @@ namespace Oyster PackageType_header, PackageType_test, PackageType_input, - PackageType_update_position + PackageType_player_pos, }; struct ProtocolHeader @@ -45,6 +45,16 @@ namespace Oyster virtual ~ProtocolTest() { delete[] f; } }; + struct ProtocolPlayerPos : public ProtocolHeader + { + int ID; + unsigned int nrOfFloats; + float *matrix; + + ProtocolPlayerPos() { this->packageType = PackageType_player_pos; } + virtual ~ProtocolPlayerPos() { delete[] matrix; } + }; + //Holding every protocol in an union. //Used because we now don't have to type case our protocol when we recieve them. @@ -56,6 +66,7 @@ namespace Oyster { ProtocolHeader* pHeader; ProtocolTest *pTest; + ProtocolPlayerPos *pPlayerPos; }Protocol; @@ -75,6 +86,12 @@ namespace Oyster delete Protocol.pTest; } break; + case PackageType_player_pos: + if(Protocol.pPlayerPos) + { + delete Protocol.pPlayerPos; + } + break; } } }; diff --git a/Code/Network/NetworkDependencies/Translator.cpp b/Code/Network/NetworkDependencies/Translator.cpp index 4bb739ca..746b00f2 100644 --- a/Code/Network/NetworkDependencies/Translator.cpp +++ b/Code/Network/NetworkDependencies/Translator.cpp @@ -17,6 +17,10 @@ void Translator::Pack( ProtocolHeader &header, OysterByte& bytes ) case PackageType_test: message = new MessageTest(); break; + + case PackageType_player_pos: + message = new MessagePlayerPos(); + break; } if(message != NULL) @@ -52,6 +56,12 @@ void Translator::Unpack(ProtocolSet* set, OysterByte& bytes ) set->Protocol.pTest = new ProtocolTest; message->Unpack(bytes, *set->Protocol.pTest); break; + + case PackageType_player_pos: + message = new MessagePlayerPos(); + set->Protocol.pPlayerPos = new ProtocolPlayerPos; + message->Unpack(bytes, *set->Protocol.pPlayerPos); + break; } if(message) diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index b8f1057f..63b1b6e5 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -54,13 +54,13 @@ void chat(Client &client) string msgSend = ""; ProtocolSet* set = new ProtocolSet; - ProtocolTest test; - test.numOfFloats = 5; - test.f = new float[test.numOfFloats]; - float temp = 12345.5654f; + ProtocolPlayerPos test; + test.ID = 5; + test.matrix = new float[16]; + float temp = 10; for(int i = 0; i < 5; i++) { - test.f[i] = temp; + test.matrix[i] = temp; temp++; } @@ -78,12 +78,20 @@ void chat(Client &client) break; case PackageType_test: cout <<"Client 2: " << set->Protocol.pTest->textMessage <Protocol.pTest->numOfFloats; i++) + for(int i = 0; i < (int)set->Protocol.pTest->numOfFloats; i++) { cout << set->Protocol.pTest->f[i] << ' ' ; } cout << endl; break; + case PackageType_player_pos: + cout << "Server: ID " << set->Protocol.pPlayerPos->ID << endl; + for(int i = 0; i < set->Protocol.pPlayerPos->nrOfFloats; i++) + { + cout << set->Protocol.pPlayerPos->matrix[i] << ' '; + } + cout << endl; + break; } set->Release(); diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 9dd0a0c1..abbf9167 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -40,17 +40,15 @@ int main() //Start listening //Accept a client - ProtocolTest test; + ProtocolPlayerPos test; test.clientID = 0; - test.size = 2; - test.textMessage = "hej"; - test.numOfFloats = 0; - test.f = new float[test.numOfFloats]; - float temp = 395.456f; - for(int i = 0; i < (int)test.numOfFloats; i++) + test.ID = 5; + test.nrOfFloats = 16; + test.matrix = new float[test.nrOfFloats]; + + for(int i = 0; i < test.nrOfFloats; i++) { - test.f[i] = temp; - temp--; + test.matrix[i] = i; } t.Pack(test, recvBuffer); From aa4cf634d3989915b8fa77a0e59a7841d673e886 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Tue, 3 Dec 2013 13:04:53 +0100 Subject: [PATCH 02/17] Client interface and class for both server and client. now using postbox system --- Code/Network/NetworkDependencies/IClient.h | 28 ++++ .../NetworkDependencies.vcxproj | 3 + .../NetworkDependencies.vcxproj.filters | 3 + .../NetworkDependencies/ThreadedClient.cpp | 123 ++++++++++++++++++ .../NetworkDependencies/ThreadedClient.h | 52 ++++++++ Code/Network/OysterNetworkClient/Client.cpp | 41 ------ Code/Network/OysterNetworkClient/Client.h | 35 ----- .../OysterNetworkClient/ClientMain.cpp | 17 +-- .../OysterNetworkClient.vcxproj | 4 - .../OysterNetworkClient.vcxproj.filters | 8 -- Code/Network/OysterNetworkServer/Client.cpp | 24 ---- Code/Network/OysterNetworkServer/Client.h | 34 ----- .../OysterNetworkServer.vcxproj | 4 - .../OysterNetworkServer.vcxproj.filters | 8 -- .../OysterNetworkServer/ServerMain.cpp | 10 +- 15 files changed, 223 insertions(+), 171 deletions(-) create mode 100644 Code/Network/NetworkDependencies/IClient.h create mode 100644 Code/Network/NetworkDependencies/ThreadedClient.cpp create mode 100644 Code/Network/NetworkDependencies/ThreadedClient.h delete mode 100644 Code/Network/OysterNetworkClient/Client.cpp delete mode 100644 Code/Network/OysterNetworkClient/Client.h delete mode 100644 Code/Network/OysterNetworkServer/Client.cpp delete mode 100644 Code/Network/OysterNetworkServer/Client.h diff --git a/Code/Network/NetworkDependencies/IClient.h b/Code/Network/NetworkDependencies/IClient.h new file mode 100644 index 00000000..bf044bae --- /dev/null +++ b/Code/Network/NetworkDependencies/IClient.h @@ -0,0 +1,28 @@ +#ifndef NETWORK_DEPENDENCIES_I_CLIENT_H +#define NETWORK_DEPENDENCIES_I_CLIENT_H + +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "../NetworkDependencies/Connection.h" +#include "../NetworkDependencies/OysterByte.h" + +namespace Oyster +{ + namespace Network + { + class IClient + { + + public: + virtual ~IClient() {}; + virtual int Send() = 0; + virtual int Recv() = 0; + + private: + + }; + } +} +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj index dfabbcba..c0a1a8a9 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj @@ -158,11 +158,13 @@ + + @@ -175,6 +177,7 @@ + diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index 74cb9a56..3474a3b6 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -10,6 +10,7 @@ + @@ -27,5 +28,7 @@ + + \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp new file mode 100644 index 00000000..73a5ebb2 --- /dev/null +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -0,0 +1,123 @@ +#include "ThreadedClient.h" + +#include +using namespace Oyster::Network; +using namespace Oyster::Thread; + + +ThreadedClient::ThreadedClient() +{ + this->connection = new Connection(); + this->sendPostBox = new PostBox(); + this->recvPostBox = NULL; +} + +ThreadedClient::ThreadedClient(unsigned int socket) +{ + this->connection = new Connection(socket); + this->sendPostBox = new PostBox(); + this->recvPostBox = NULL; +} + +ThreadedClient::~ThreadedClient() +{ + thread.Terminate(); + delete this->connection; + this->connection = NULL; + this->recvPostBox = NULL; + + if(sendPostBox != NULL) + { + delete sendPostBox; + this->sendPostBox = NULL; + } +} + +int ThreadedClient::Send(OysterByte* byte) +{ + this->sendPostBox->PostMessage(byte); + return 0; +} + +int ThreadedClient::Send() +{ + int errorCode = 0; + mutex.LockMutex(); + if(!sendPostBox->IsFull()) + { + OysterByte *temp = NULL; + sendPostBox->FetchMessage(temp); + errorCode = this->connection->Send(*temp); + mutex.UnlockMutex(); + } + + return errorCode; +} + +int ThreadedClient::Recv() +{ + int errorCode = 0; + mutex.LockMutex(); + if(!recvPostBox->IsFull()) + { + OysterByte *temp = NULL; + errorCode = this->connection->Recieve(*temp); + recvPostBox->PostMessage(temp); + mutex.UnlockMutex(); + } + return errorCode; +} + +void ThreadedClient::ThreadEntry() +{ + std::cout<< "Thread started" << std::endl; +} + +void ThreadedClient::ThreadExit() +{ + std::cout << "Thread exit" << std::endl; +} + +bool ThreadedClient::DoWork() +{ + int errorCode; + errorCode = Send(); + + if(errorCode != 0) + { + return false; + } + + errorCode = Recv(); + if(errorCode != 0) + { + return false; + } + + return true; +} + +int ThreadedClient::Connect(unsigned short port, const char serverName[]) +{ + int errorCode; + + if((errorCode = connection->InitiateClient()) != 0) + { + return errorCode; + } + + else if((errorCode = connection->Connect(port, serverName)) != 0) + { + return errorCode; + } + + thread.Create(this, true); + return 0; +} + +void ThreadedClient::setRecvPostBox(IPostBox* postBox) +{ + this->mutex.LockMutex(); + this->recvPostBox = postBox; + this->mutex.UnlockMutex(); +} \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/ThreadedClient.h b/Code/Network/NetworkDependencies/ThreadedClient.h new file mode 100644 index 00000000..384fe96c --- /dev/null +++ b/Code/Network/NetworkDependencies/ThreadedClient.h @@ -0,0 +1,52 @@ +#ifndef NETWORK_DEPENDENCIES_THREADED_CLIENT_H +#define NETWORK_DEPENDENCIES_THREADED_CLIENT_H + +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "../NetworkDependencies/IClient.h" +#include "../../Misc/Thread/IThreadObject.h" +#include "../NetworkDependencies/PostBox.h" +#include "../../Misc/Thread/OysterThread.h" +#include "../../Misc/Thread/OysterMutex.h" + +namespace Oyster +{ + namespace Network + { + class ThreadedClient : public IClient, public Thread::IThreadObject + { + public: + ThreadedClient(); + ThreadedClient(unsigned int socket); + virtual ~ThreadedClient(); + + int Send(OysterByte* byte); + + int Connect(unsigned short port, const char serverName[]); + + void setRecvPostBox(IPostBox* postBox); + private: + + virtual int Send(); + virtual int Recv(); + + virtual void ThreadEntry(); + virtual void ThreadExit(); + virtual bool DoWork(); + + + + + Connection* connection; + IPostBox* sendPostBox; + IPostBox* recvPostBox; + Oyster::Thread::OysterThread thread; + OysterMutex mutex; + + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/Client.cpp b/Code/Network/OysterNetworkClient/Client.cpp deleted file mode 100644 index daffe9b6..00000000 --- a/Code/Network/OysterNetworkClient/Client.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "Client.h" - -using namespace Oyster::Network::Client; - -Client::Client() -{ - connection = new Connection(); -} - -Client::~Client() -{ - delete this->connection; - connection = 0; -} - -int Client::Connect(unsigned int port, char filename[]) -{ - int errorCode; - - if((errorCode = connection->InitiateClient()) != 0) - { - return errorCode; - } - - if((errorCode = connection->Connect(port, filename)) != 0) - { - return errorCode; - } - - return 0; -} - -void Client::Send(Oyster::Network::OysterByte& bytes) -{ - connection->Send(bytes); -} - -void Client::Recv(Oyster::Network::OysterByte& bytes) -{ - connection->Recieve(bytes); -} \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/Client.h b/Code/Network/OysterNetworkClient/Client.h deleted file mode 100644 index 6e69e657..00000000 --- a/Code/Network/OysterNetworkClient/Client.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef NETWORK_CLIENT_CLIENT_H -#define NETWORK_CLIENT_CLIENT_H - -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "../NetworkDependencies/Connection.h" -#include "../NetworkDependencies/OysterByte.h" - -namespace Oyster -{ - namespace Network - { - namespace Client - { - class Client - { - public: - Client(); - ~Client(); - - int Connect(unsigned int port, char filename[]); - - void Send(OysterByte& bytes); - void Recv(OysterByte& bytes); - - private: - ::Oyster::Network::Connection* connection; - }; - } - } -} - -#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index b8f1057f..60c9453f 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -6,15 +6,15 @@ #include "..\NetworkDependencies\Protocols.h" #include "../NetworkDependencies/OysterByte.h" #include "../../Misc/ThreadSafeQueue.h" -#include "Client.h" +#include "../NetworkDependencies/ThreadedClient.h" #pragma comment(lib, "ws2_32.lib") using namespace std; using namespace Oyster::Network::Protocols; -using namespace Oyster::Network::Client; +using namespace Oyster::Network; -void chat(Client &client); +void chat(ThreadedClient &client); int main() { @@ -27,7 +27,7 @@ int main() cout << "Client" << endl; //Create Client - Client client; + ThreadedClient client; //Connect to server errorCode = client.Connect(9876, "localhost"); @@ -38,7 +38,7 @@ int main() wcout << "errorMessage: " << errorTest << endl; } - chat(client); + //chat(client); ShutdownWinSock(); @@ -46,7 +46,7 @@ int main() return 0; } -void chat(Client &client) +void chat(ThreadedClient &client) { Oyster::Network::Translator *t = new Oyster::Network::Translator(); @@ -65,7 +65,7 @@ void chat(Client &client) } bool chatDone = false; - + /* while(!chatDone) { client.Recv(msgRecv); @@ -113,9 +113,10 @@ void chat(Client &client) } cin.clear();*/ - + /* } delete t; delete set; + */ } \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj index f4e13099..bb63d4cf 100644 --- a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj +++ b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj @@ -154,12 +154,8 @@ - - - - diff --git a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters index 2e5e9ef6..cd4a498b 100644 --- a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters +++ b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters @@ -18,13 +18,5 @@ Source Files - - Source Files - - - - - Header Files - \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/Client.cpp b/Code/Network/OysterNetworkServer/Client.cpp deleted file mode 100644 index 5cc15eec..00000000 --- a/Code/Network/OysterNetworkServer/Client.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "Client.h" - -using namespace Oyster::Network; -using namespace Oyster::Network::Server; - -Client::Client(unsigned int socket) -{ - connection = new Connection(socket); -} - -Client::~Client() -{ - delete connection; -} - -void Client::Send(OysterByte& bytes) -{ - connection->Send(bytes); -} - -void Client::Recv(OysterByte& bytes) -{ - connection->Recieve(bytes); -} \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/Client.h b/Code/Network/OysterNetworkServer/Client.h deleted file mode 100644 index 2c5ba35f..00000000 --- a/Code/Network/OysterNetworkServer/Client.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef NETWORK_SERVER_CLIENT_H -#define NETWORK_SERVER_CLIENT_H - -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "../NetworkDependencies/Connection.h" -#include "../NetworkDependencies/OysterByte.h" - -namespace Oyster -{ - namespace Network - { - namespace Server - { - class Client - { - public: - Client(unsigned int socket); - ~Client(); - - void Send(OysterByte& bytes); - void Recv(OysterByte& bytes); - - private: - ::Oyster::Network::Connection* connection; - - }; - } - } -}; - -#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj index 65136729..d2268387 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj @@ -154,12 +154,8 @@ - - - - diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters index 3cb5827c..f8025a15 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters @@ -18,13 +18,5 @@ Source Files - - Source Files - - - - - Header Files - \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 9dd0a0c1..cc80b165 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -5,7 +5,7 @@ #include "../NetworkDependencies/WinsockFunctions.h" #include "../NetworkDependencies/Listener.h" #include "../NetworkDependencies/Translator.h" -#include "Client.h" +#include "../NetworkDependencies/ThreadedClient.h" #include "../NetworkDependencies/OysterByte.h" #include "../NetworkDependencies/PostBox.h" #include "../../Misc/WinTimer.h" @@ -57,7 +57,7 @@ int main() WinTimer timer; - vector clients; + vector clients; int client = -1; while(1) { @@ -66,9 +66,9 @@ int main() if(client != -1) { cout << "Client connected: " << client << endl; - clients.push_back(new Client(client)); + clients.push_back(new ThreadedClient(client)); - clients.at(clients.size()-1)->Send(recvBuffer); + clients.at(clients.size()-1)->Send(&recvBuffer); } //Send a message every 1 secounds to all clients. @@ -78,7 +78,7 @@ int main() timer.reset(); for(int i = 0; i < (int)clients.size(); i++) { - clients.at(i)->Send(recvBuffer); + clients.at(i)->Send(&recvBuffer); } } Sleep(100); From 10c1dc57f3c9235ca6c6d4e69fed43465daa7752 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Tue, 3 Dec 2013 13:08:04 +0100 Subject: [PATCH 03/17] merge fix --- Code/Network/NetworkDependencies/IClient.h | 28 ++++ .../NetworkDependencies.vcxproj | 3 + .../NetworkDependencies.vcxproj.filters | 7 + .../NetworkDependencies/ThreadedClient.cpp | 123 ++++++++++++++++++ .../NetworkDependencies/ThreadedClient.h | 52 ++++++++ Code/Network/OysterNetworkClient/Client.cpp | 41 ------ Code/Network/OysterNetworkClient/Client.h | 35 ----- .../OysterNetworkClient/ClientMain.cpp | 17 +-- .../OysterNetworkClient.vcxproj | 4 - .../OysterNetworkClient.vcxproj.filters | 8 -- Code/Network/OysterNetworkServer/Client.cpp | 24 ---- Code/Network/OysterNetworkServer/Client.h | 34 ----- .../OysterNetworkServer.vcxproj | 4 - .../OysterNetworkServer.vcxproj.filters | 8 -- .../OysterNetworkServer/ServerMain.cpp | 10 +- 15 files changed, 227 insertions(+), 171 deletions(-) create mode 100644 Code/Network/NetworkDependencies/IClient.h create mode 100644 Code/Network/NetworkDependencies/ThreadedClient.cpp create mode 100644 Code/Network/NetworkDependencies/ThreadedClient.h delete mode 100644 Code/Network/OysterNetworkClient/Client.cpp delete mode 100644 Code/Network/OysterNetworkClient/Client.h delete mode 100644 Code/Network/OysterNetworkServer/Client.cpp delete mode 100644 Code/Network/OysterNetworkServer/Client.h diff --git a/Code/Network/NetworkDependencies/IClient.h b/Code/Network/NetworkDependencies/IClient.h new file mode 100644 index 00000000..bf044bae --- /dev/null +++ b/Code/Network/NetworkDependencies/IClient.h @@ -0,0 +1,28 @@ +#ifndef NETWORK_DEPENDENCIES_I_CLIENT_H +#define NETWORK_DEPENDENCIES_I_CLIENT_H + +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "../NetworkDependencies/Connection.h" +#include "../NetworkDependencies/OysterByte.h" + +namespace Oyster +{ + namespace Network + { + class IClient + { + + public: + virtual ~IClient() {}; + virtual int Send() = 0; + virtual int Recv() = 0; + + private: + + }; + } +} +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj index 129568cc..d320872f 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj @@ -159,11 +159,13 @@ + + @@ -177,6 +179,7 @@ + diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index e26441c6..de894c8b 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -11,6 +11,8 @@ + + @@ -28,6 +30,11 @@ +<<<<<<< HEAD +======= + + +>>>>>>> Client interface and class for both server and client. now using postbox system \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp new file mode 100644 index 00000000..73a5ebb2 --- /dev/null +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -0,0 +1,123 @@ +#include "ThreadedClient.h" + +#include +using namespace Oyster::Network; +using namespace Oyster::Thread; + + +ThreadedClient::ThreadedClient() +{ + this->connection = new Connection(); + this->sendPostBox = new PostBox(); + this->recvPostBox = NULL; +} + +ThreadedClient::ThreadedClient(unsigned int socket) +{ + this->connection = new Connection(socket); + this->sendPostBox = new PostBox(); + this->recvPostBox = NULL; +} + +ThreadedClient::~ThreadedClient() +{ + thread.Terminate(); + delete this->connection; + this->connection = NULL; + this->recvPostBox = NULL; + + if(sendPostBox != NULL) + { + delete sendPostBox; + this->sendPostBox = NULL; + } +} + +int ThreadedClient::Send(OysterByte* byte) +{ + this->sendPostBox->PostMessage(byte); + return 0; +} + +int ThreadedClient::Send() +{ + int errorCode = 0; + mutex.LockMutex(); + if(!sendPostBox->IsFull()) + { + OysterByte *temp = NULL; + sendPostBox->FetchMessage(temp); + errorCode = this->connection->Send(*temp); + mutex.UnlockMutex(); + } + + return errorCode; +} + +int ThreadedClient::Recv() +{ + int errorCode = 0; + mutex.LockMutex(); + if(!recvPostBox->IsFull()) + { + OysterByte *temp = NULL; + errorCode = this->connection->Recieve(*temp); + recvPostBox->PostMessage(temp); + mutex.UnlockMutex(); + } + return errorCode; +} + +void ThreadedClient::ThreadEntry() +{ + std::cout<< "Thread started" << std::endl; +} + +void ThreadedClient::ThreadExit() +{ + std::cout << "Thread exit" << std::endl; +} + +bool ThreadedClient::DoWork() +{ + int errorCode; + errorCode = Send(); + + if(errorCode != 0) + { + return false; + } + + errorCode = Recv(); + if(errorCode != 0) + { + return false; + } + + return true; +} + +int ThreadedClient::Connect(unsigned short port, const char serverName[]) +{ + int errorCode; + + if((errorCode = connection->InitiateClient()) != 0) + { + return errorCode; + } + + else if((errorCode = connection->Connect(port, serverName)) != 0) + { + return errorCode; + } + + thread.Create(this, true); + return 0; +} + +void ThreadedClient::setRecvPostBox(IPostBox* postBox) +{ + this->mutex.LockMutex(); + this->recvPostBox = postBox; + this->mutex.UnlockMutex(); +} \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/ThreadedClient.h b/Code/Network/NetworkDependencies/ThreadedClient.h new file mode 100644 index 00000000..384fe96c --- /dev/null +++ b/Code/Network/NetworkDependencies/ThreadedClient.h @@ -0,0 +1,52 @@ +#ifndef NETWORK_DEPENDENCIES_THREADED_CLIENT_H +#define NETWORK_DEPENDENCIES_THREADED_CLIENT_H + +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "../NetworkDependencies/IClient.h" +#include "../../Misc/Thread/IThreadObject.h" +#include "../NetworkDependencies/PostBox.h" +#include "../../Misc/Thread/OysterThread.h" +#include "../../Misc/Thread/OysterMutex.h" + +namespace Oyster +{ + namespace Network + { + class ThreadedClient : public IClient, public Thread::IThreadObject + { + public: + ThreadedClient(); + ThreadedClient(unsigned int socket); + virtual ~ThreadedClient(); + + int Send(OysterByte* byte); + + int Connect(unsigned short port, const char serverName[]); + + void setRecvPostBox(IPostBox* postBox); + private: + + virtual int Send(); + virtual int Recv(); + + virtual void ThreadEntry(); + virtual void ThreadExit(); + virtual bool DoWork(); + + + + + Connection* connection; + IPostBox* sendPostBox; + IPostBox* recvPostBox; + Oyster::Thread::OysterThread thread; + OysterMutex mutex; + + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/Client.cpp b/Code/Network/OysterNetworkClient/Client.cpp deleted file mode 100644 index daffe9b6..00000000 --- a/Code/Network/OysterNetworkClient/Client.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "Client.h" - -using namespace Oyster::Network::Client; - -Client::Client() -{ - connection = new Connection(); -} - -Client::~Client() -{ - delete this->connection; - connection = 0; -} - -int Client::Connect(unsigned int port, char filename[]) -{ - int errorCode; - - if((errorCode = connection->InitiateClient()) != 0) - { - return errorCode; - } - - if((errorCode = connection->Connect(port, filename)) != 0) - { - return errorCode; - } - - return 0; -} - -void Client::Send(Oyster::Network::OysterByte& bytes) -{ - connection->Send(bytes); -} - -void Client::Recv(Oyster::Network::OysterByte& bytes) -{ - connection->Recieve(bytes); -} \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/Client.h b/Code/Network/OysterNetworkClient/Client.h deleted file mode 100644 index 6e69e657..00000000 --- a/Code/Network/OysterNetworkClient/Client.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef NETWORK_CLIENT_CLIENT_H -#define NETWORK_CLIENT_CLIENT_H - -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "../NetworkDependencies/Connection.h" -#include "../NetworkDependencies/OysterByte.h" - -namespace Oyster -{ - namespace Network - { - namespace Client - { - class Client - { - public: - Client(); - ~Client(); - - int Connect(unsigned int port, char filename[]); - - void Send(OysterByte& bytes); - void Recv(OysterByte& bytes); - - private: - ::Oyster::Network::Connection* connection; - }; - } - } -} - -#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index 63b1b6e5..bbf2ec6f 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -6,15 +6,15 @@ #include "..\NetworkDependencies\Protocols.h" #include "../NetworkDependencies/OysterByte.h" #include "../../Misc/ThreadSafeQueue.h" -#include "Client.h" +#include "../NetworkDependencies/ThreadedClient.h" #pragma comment(lib, "ws2_32.lib") using namespace std; using namespace Oyster::Network::Protocols; -using namespace Oyster::Network::Client; +using namespace Oyster::Network; -void chat(Client &client); +void chat(ThreadedClient &client); int main() { @@ -27,7 +27,7 @@ int main() cout << "Client" << endl; //Create Client - Client client; + ThreadedClient client; //Connect to server errorCode = client.Connect(9876, "localhost"); @@ -38,7 +38,7 @@ int main() wcout << "errorMessage: " << errorTest << endl; } - chat(client); + //chat(client); ShutdownWinSock(); @@ -46,7 +46,7 @@ int main() return 0; } -void chat(Client &client) +void chat(ThreadedClient &client) { Oyster::Network::Translator *t = new Oyster::Network::Translator(); @@ -65,7 +65,7 @@ void chat(Client &client) } bool chatDone = false; - + /* while(!chatDone) { client.Recv(msgRecv); @@ -121,9 +121,10 @@ void chat(Client &client) } cin.clear();*/ - + /* } delete t; delete set; + */ } \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj index f4e13099..bb63d4cf 100644 --- a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj +++ b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj @@ -154,12 +154,8 @@ - - - - diff --git a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters index 2e5e9ef6..cd4a498b 100644 --- a/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters +++ b/Code/Network/OysterNetworkClient/OysterNetworkClient.vcxproj.filters @@ -18,13 +18,5 @@ Source Files - - Source Files - - - - - Header Files - \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/Client.cpp b/Code/Network/OysterNetworkServer/Client.cpp deleted file mode 100644 index 5cc15eec..00000000 --- a/Code/Network/OysterNetworkServer/Client.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "Client.h" - -using namespace Oyster::Network; -using namespace Oyster::Network::Server; - -Client::Client(unsigned int socket) -{ - connection = new Connection(socket); -} - -Client::~Client() -{ - delete connection; -} - -void Client::Send(OysterByte& bytes) -{ - connection->Send(bytes); -} - -void Client::Recv(OysterByte& bytes) -{ - connection->Recieve(bytes); -} \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/Client.h b/Code/Network/OysterNetworkServer/Client.h deleted file mode 100644 index 2c5ba35f..00000000 --- a/Code/Network/OysterNetworkServer/Client.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef NETWORK_SERVER_CLIENT_H -#define NETWORK_SERVER_CLIENT_H - -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "../NetworkDependencies/Connection.h" -#include "../NetworkDependencies/OysterByte.h" - -namespace Oyster -{ - namespace Network - { - namespace Server - { - class Client - { - public: - Client(unsigned int socket); - ~Client(); - - void Send(OysterByte& bytes); - void Recv(OysterByte& bytes); - - private: - ::Oyster::Network::Connection* connection; - - }; - } - } -}; - -#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj index 65136729..d2268387 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj @@ -154,12 +154,8 @@ - - - - diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters index 3cb5827c..f8025a15 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters @@ -18,13 +18,5 @@ Source Files - - Source Files - - - - - Header Files - \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index abbf9167..f1014f59 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -5,7 +5,7 @@ #include "../NetworkDependencies/WinsockFunctions.h" #include "../NetworkDependencies/Listener.h" #include "../NetworkDependencies/Translator.h" -#include "Client.h" +#include "../NetworkDependencies/ThreadedClient.h" #include "../NetworkDependencies/OysterByte.h" #include "../NetworkDependencies/PostBox.h" #include "../../Misc/WinTimer.h" @@ -55,7 +55,7 @@ int main() WinTimer timer; - vector clients; + vector clients; int client = -1; while(1) { @@ -64,9 +64,9 @@ int main() if(client != -1) { cout << "Client connected: " << client << endl; - clients.push_back(new Client(client)); + clients.push_back(new ThreadedClient(client)); - clients.at(clients.size()-1)->Send(recvBuffer); + clients.at(clients.size()-1)->Send(&recvBuffer); } //Send a message every 1 secounds to all clients. @@ -76,7 +76,7 @@ int main() timer.reset(); for(int i = 0; i < (int)clients.size(); i++) { - clients.at(i)->Send(recvBuffer); + clients.at(i)->Send(&recvBuffer); } } Sleep(100); From 1466c0db314bf33fa447cba09e7aefe71ff2510a Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Tue, 3 Dec 2013 13:16:44 +0100 Subject: [PATCH 04/17] Network - projectfile fix --- .../NetworkDependencies/NetworkDependencies.vcxproj.filters | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index d3c0b9e5..083f7a1d 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -30,16 +30,10 @@ -<<<<<<< HEAD -======= -<<<<<<< HEAD -======= ->>>>>>> Client interface and class for both server and client. now using postbox system ->>>>>>> 10c1dc57f3c9235ca6c6d4e69fed43465daa7752 \ No newline at end of file From e837b80e43788cba093cb6bbe6b1db4bb9b08770 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 3 Dec 2013 13:07:04 +0100 Subject: [PATCH 05/17] Network - Fixed warning, made functions private. Fixed warnings. Made functions regarding the thread private in listener. --- Code/Network/NetworkDependencies/Listener.cpp | 2 +- Code/Network/NetworkDependencies/Listener.h | 3 +-- Code/Network/OysterNetworkServer/ServerMain.cpp | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Code/Network/NetworkDependencies/Listener.cpp b/Code/Network/NetworkDependencies/Listener.cpp index c441d045..05616aec 100644 --- a/Code/Network/NetworkDependencies/Listener.cpp +++ b/Code/Network/NetworkDependencies/Listener.cpp @@ -28,7 +28,7 @@ bool Listener::Init(unsigned int port) void Listener::Shutdown() { - thread.Terminate(); + thread.Stop(); } void Listener::SetPostBox(Oyster::Network::IPostBox* postBox) diff --git a/Code/Network/NetworkDependencies/Listener.h b/Code/Network/NetworkDependencies/Listener.h index 8bb16a0f..469e30c6 100644 --- a/Code/Network/NetworkDependencies/Listener.h +++ b/Code/Network/NetworkDependencies/Listener.h @@ -28,16 +28,15 @@ namespace Oyster void SetPostBox(IPostBox* postBox); + private: //Thread functions bool DoWork(); void ThreadEntry(); void ThreadExit(); - private: //Function that runs in the thread. int Accept(); - private: ::Oyster::Network::Connection* connection; diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index f1014f59..ec35b1e1 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -46,9 +46,9 @@ int main() test.nrOfFloats = 16; test.matrix = new float[test.nrOfFloats]; - for(int i = 0; i < test.nrOfFloats; i++) + for(int i = 0; i < (int)test.nrOfFloats; i++) { - test.matrix[i] = i; + test.matrix[i] = (float)i; } t.Pack(test, recvBuffer); From df1470eb2ce54e843b44b4e38bebe08309e620f6 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 3 Dec 2013 23:12:48 +0100 Subject: [PATCH 06/17] Network - Send/Recv both ways. Impl: SetBlockingMode() : Connection. Impl: Resize() : OysterByte. Remade Clear() : OysterByte. Added bool return if FetchMessage() succeded or failed : PostBox. Fixed a few errors with mutex on ThreadedClient. Added missing mutex unlock in ThreadSafeQueue. --- Code/Misc/ThreadSafeQueue.h | 2 + .../NetworkDependencies/Connection.cpp | 21 ++-- Code/Network/NetworkDependencies/Connection.h | 5 +- Code/Network/NetworkDependencies/IPostBox.h | 2 +- .../NetworkDependencies/OysterByte.cpp | 13 +- Code/Network/NetworkDependencies/OysterByte.h | 3 +- Code/Network/NetworkDependencies/PostBox.h | 8 +- .../NetworkDependencies/ThreadedClient.cpp | 50 +++++--- .../NetworkDependencies/ThreadedClient.h | 7 +- .../OysterNetworkClient/ClientMain.cpp | 118 +++++++++--------- .../OysterNetworkServer/ServerMain.cpp | 101 ++++++++------- 11 files changed, 188 insertions(+), 142 deletions(-) diff --git a/Code/Misc/ThreadSafeQueue.h b/Code/Misc/ThreadSafeQueue.h index d0125f71..19775f55 100644 --- a/Code/Misc/ThreadSafeQueue.h +++ b/Code/Misc/ThreadSafeQueue.h @@ -132,6 +132,7 @@ namespace Oyster this->front = NULL; this->back = NULL; } + mutex.UnlockMutex(); return item; } @@ -146,6 +147,7 @@ namespace Oyster mutex.LockMutex(); if(front != NULL) { + mutex.UnlockMutex(); return this->front->item; } mutex.UnlockMutex(); diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 3f303542..19556bbd 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -96,7 +96,7 @@ int Connection::Recieve(OysterByte& bytes) { int nBytes; - bytes.Clear(1000); + bytes.Resize(1000); nBytes = recv(this->socket, bytes, 500, 0); if(nBytes == SOCKET_ERROR) { @@ -109,8 +109,6 @@ int Connection::Recieve(OysterByte& bytes) std::cout << "Size of the recieved data: " << nBytes << " bytes" << std::endl; - //bytes.byteArray[nBytes] = '\0'; - return 0; } @@ -139,15 +137,24 @@ int Connection::InitiateSocket() return 0; } -void Connection::SetBlockingMode(bool blocking) +int Connection::SetBlockingMode(bool blocking) { - //TODO: Implement this function. Setting the socket to blocking or non-blocking. + DWORD nonBlocking; + if(blocking) { - //fcntl(this->socket, F_SETFL, O_NONBLOCK); + nonBlocking = 0; } else { - + nonBlocking = 1; } + + int result = ioctlsocket(this->socket, FIONBIO, &nonBlocking); + if(result != 0) + { + return WSAGetLastError(); + } + + return 0; } \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Connection.h b/Code/Network/NetworkDependencies/Connection.h index b46ccb02..27933abf 100644 --- a/Code/Network/NetworkDependencies/Connection.h +++ b/Code/Network/NetworkDependencies/Connection.h @@ -20,7 +20,6 @@ namespace Oyster Connection( int socket ) { this->socket = socket; }; virtual ~Connection(); - virtual int InitiateServer( unsigned short port ); virtual int InitiateClient(); @@ -32,9 +31,11 @@ namespace Oyster virtual int Listen(); + //Setting the socket to blocking/non-blocking mode. + int SetBlockingMode( bool blocking ); + private: int InitiateSocket(); - void SetBlockingMode( bool blocking ); int socket; diff --git a/Code/Network/NetworkDependencies/IPostBox.h b/Code/Network/NetworkDependencies/IPostBox.h index 31c1bef7..70dc7558 100644 --- a/Code/Network/NetworkDependencies/IPostBox.h +++ b/Code/Network/NetworkDependencies/IPostBox.h @@ -15,7 +15,7 @@ namespace Oyster public: virtual ~IPostBox() {} virtual void PostMessage(T& message) = 0; - virtual void FetchMessage(T& message) = 0; + virtual bool FetchMessage(T& message) = 0; virtual bool IsFull() = 0; }; diff --git a/Code/Network/NetworkDependencies/OysterByte.cpp b/Code/Network/NetworkDependencies/OysterByte.cpp index ef7aa434..8df493f1 100644 --- a/Code/Network/NetworkDependencies/OysterByte.cpp +++ b/Code/Network/NetworkDependencies/OysterByte.cpp @@ -21,13 +21,20 @@ OysterByte::~OysterByte() delete[] byteArray; } -void OysterByte::Clear(unsigned int cap) +void OysterByte::Clear() { - delete[] byteArray; - byteArray = new unsigned char[cap]; size = 0; } +void OysterByte::Resize(unsigned int cap) +{ + if(capacity < cap) + { + delete[] byteArray; + byteArray = new unsigned char[cap]; + } +} + int OysterByte::GetSize() { return size; diff --git a/Code/Network/NetworkDependencies/OysterByte.h b/Code/Network/NetworkDependencies/OysterByte.h index 87a0103c..9a6bc75a 100644 --- a/Code/Network/NetworkDependencies/OysterByte.h +++ b/Code/Network/NetworkDependencies/OysterByte.h @@ -18,7 +18,8 @@ namespace Oyster OysterByte(int cap); virtual ~OysterByte(); - void Clear(unsigned int cap); + void Clear(); //Resets size to 0 + void Resize(unsigned int cap); //Resizes the array with, it does not keep anything in it. int GetSize(); unsigned char* GetByteArray(); diff --git a/Code/Network/NetworkDependencies/PostBox.h b/Code/Network/NetworkDependencies/PostBox.h index b2e553f8..960b6f34 100644 --- a/Code/Network/NetworkDependencies/PostBox.h +++ b/Code/Network/NetworkDependencies/PostBox.h @@ -23,7 +23,7 @@ namespace Oyster virtual ~PostBox(); virtual void PostMessage(T& message); - virtual void FetchMessage(T& message); + virtual bool FetchMessage(T& message); virtual bool IsFull(); private: @@ -49,13 +49,15 @@ namespace Oyster } template - void PostBox::FetchMessage(T& message) + bool PostBox::FetchMessage(T& message) { if(IsFull()) { message = messages.Front(); - messages.Pop(); + messages.Pop(); + return true; } + return false; } template diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp index 73a5ebb2..dafe70b8 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.cpp +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -4,7 +4,6 @@ using namespace Oyster::Network; using namespace Oyster::Thread; - ThreadedClient::ThreadedClient() { this->connection = new Connection(); @@ -17,6 +16,21 @@ ThreadedClient::ThreadedClient(unsigned int socket) this->connection = new Connection(socket); this->sendPostBox = new PostBox(); this->recvPostBox = NULL; + + connection->SetBlockingMode(false); + + thread.Create(this, true); +} + +ThreadedClient::ThreadedClient(IPostBox* postBox, unsigned int socket) +{ + this->connection = new Connection(socket); + this->sendPostBox = new PostBox; + this->recvPostBox = postBox; + + connection->SetBlockingMode(false); + + thread.Create(this, true); } ThreadedClient::~ThreadedClient() @@ -35,7 +49,9 @@ ThreadedClient::~ThreadedClient() int ThreadedClient::Send(OysterByte* byte) { + mutex.LockMutex(); this->sendPostBox->PostMessage(byte); + mutex.UnlockMutex(); return 0; } @@ -43,13 +59,13 @@ int ThreadedClient::Send() { int errorCode = 0; mutex.LockMutex(); - if(!sendPostBox->IsFull()) + if(sendPostBox->IsFull()) { OysterByte *temp = NULL; sendPostBox->FetchMessage(temp); errorCode = this->connection->Send(*temp); - mutex.UnlockMutex(); } + mutex.UnlockMutex(); return errorCode; } @@ -57,42 +73,48 @@ int ThreadedClient::Send() int ThreadedClient::Recv() { int errorCode = 0; - mutex.LockMutex(); - if(!recvPostBox->IsFull()) + + OysterByte *temp = new OysterByte(); + errorCode = this->connection->Recieve(*temp); + + if(errorCode == 0) { - OysterByte *temp = NULL; - errorCode = this->connection->Recieve(*temp); + mutex.LockMutex(); recvPostBox->PostMessage(temp); mutex.UnlockMutex(); } + else + { + delete temp; + } + return errorCode; } void ThreadedClient::ThreadEntry() { - std::cout<< "Thread started" << std::endl; + std::cout<< "Client Thread started" << std::endl; } void ThreadedClient::ThreadExit() { - std::cout << "Thread exit" << std::endl; + std::cout << "Client Thread exit" << std::endl; } bool ThreadedClient::DoWork() { int errorCode; errorCode = Send(); - - if(errorCode != 0) + /*if(errorCode != 0) { return false; - } + }*/ errorCode = Recv(); - if(errorCode != 0) + /*if(errorCode != 0) { return false; - } + }*/ return true; } diff --git a/Code/Network/NetworkDependencies/ThreadedClient.h b/Code/Network/NetworkDependencies/ThreadedClient.h index 384fe96c..dbf99347 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.h +++ b/Code/Network/NetworkDependencies/ThreadedClient.h @@ -20,6 +20,7 @@ namespace Oyster public: ThreadedClient(); ThreadedClient(unsigned int socket); + ThreadedClient(IPostBox* postBox, unsigned int socket); virtual ~ThreadedClient(); int Send(OysterByte* byte); @@ -27,8 +28,8 @@ namespace Oyster int Connect(unsigned short port, const char serverName[]); void setRecvPostBox(IPostBox* postBox); - private: + private: virtual int Send(); virtual int Recv(); @@ -36,9 +37,7 @@ namespace Oyster virtual void ThreadExit(); virtual bool DoWork(); - - - + private: Connection* connection; IPostBox* sendPostBox; IPostBox* recvPostBox; diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index bbf2ec6f..45861c96 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -7,14 +7,18 @@ #include "../NetworkDependencies/OysterByte.h" #include "../../Misc/ThreadSafeQueue.h" #include "../NetworkDependencies/ThreadedClient.h" +#include "../../Misc/WinTimer.h" +#include "../../Misc/Utilities.h" #pragma comment(lib, "ws2_32.lib") using namespace std; using namespace Oyster::Network::Protocols; using namespace Oyster::Network; +using namespace Utility; void chat(ThreadedClient &client); +void PrintOutMessage(ProtocolSet* set); int main() { @@ -27,10 +31,10 @@ int main() cout << "Client" << endl; //Create Client - ThreadedClient client; + ThreadedClient* client = new ThreadedClient; //Connect to server - errorCode = client.Connect(9876, "localhost"); + errorCode = client->Connect(9876, "localhost"); if(errorCode != 0) { @@ -38,7 +42,8 @@ int main() wcout << "errorMessage: " << errorTest << endl; } - //chat(client); + chat(*client); + delete client; ShutdownWinSock(); @@ -49,82 +54,77 @@ int main() void chat(ThreadedClient &client) { Oyster::Network::Translator *t = new Oyster::Network::Translator(); + IPostBox* postBox = new PostBox; - Oyster::Network::OysterByte msgRecv; - string msgSend = ""; + client.setRecvPostBox(postBox); + + Oyster::Network::OysterByte* msgRecv = NULL; + Oyster::Network::OysterByte* msgSend = new OysterByte(); ProtocolSet* set = new ProtocolSet; ProtocolPlayerPos test; test.ID = 5; - test.matrix = new float[16]; + test.nrOfFloats = 5; + test.matrix = new float[test.nrOfFloats]; float temp = 10; - for(int i = 0; i < 5; i++) + for(int i = 0; i < (int)test.nrOfFloats; i++) { test.matrix[i] = temp; temp++; } + t->Pack(test, *msgSend); - bool chatDone = false; - /* - while(!chatDone) + WinTimer timer; + + while(1) { - client.Recv(msgRecv); - - t->Unpack(set, msgRecv); - - switch(set->type) + //Fetch new messages from the postbox + if(postBox->FetchMessage(msgRecv)) { - case PackageType_header: - break; - case PackageType_test: - cout <<"Client 2: " << set->Protocol.pTest->textMessage <Protocol.pTest->numOfFloats; i++) - { - cout << set->Protocol.pTest->f[i] << ' ' ; - } - cout << endl; - break; - case PackageType_player_pos: - cout << "Server: ID " << set->Protocol.pPlayerPos->ID << endl; - for(int i = 0; i < set->Protocol.pPlayerPos->nrOfFloats; i++) - { - cout << set->Protocol.pPlayerPos->matrix[i] << ' '; - } - cout << endl; - break; - } - - set->Release(); - msgRecv.Clear(1000); + t->Unpack(set, *msgRecv); + delete msgRecv; - /*std::getline(std::cin, msgSend); - - - - if( msgSend != "exit") - { - if(msgSend.length() < 1) - { - msgSend = "ERROR!"; - } - - test.textMessage = msgSend; - - t->Pack(test, msgRecv); - - client.Send(msgRecv); + PrintOutMessage(set); + set->Release(); } - else + //Send message to server each second + if(timer.getElapsedSeconds() > 1) { - chatDone = true; + cout << "Sending to server." << endl; + timer.reset(); + client.Send(msgSend); } - - cin.clear();*/ - /* } + delete msgSend; + delete postBox; delete t; delete set; - */ +} + +void PrintOutMessage(ProtocolSet* set) +{ + switch(set->type) + { + case PackageType_header: + break; + case PackageType_test: + cout <<"Client 2: " << set->Protocol.pTest->textMessage <Protocol.pTest->numOfFloats; i++) + { + cout << set->Protocol.pTest->f[i] << ' ' ; + } + cout << endl; + break; + + case PackageType_player_pos: + cout << "ID " << set->Protocol.pPlayerPos->ID << endl; + for(int i = 0; i < (int)set->Protocol.pPlayerPos->nrOfFloats; i++) + { + cout << set->Protocol.pPlayerPos->matrix[i] << ' '; + } + cout << endl; + break; + } } \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index ec35b1e1..95a07641 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -18,10 +18,15 @@ using namespace Oyster::Network; using namespace ::Protocols; using namespace Utility; +void PrintOutMessage(ProtocolSet* set); + int main() { - OysterByte recvBuffer; + OysterByte sendBuffer; + OysterByte* recvBuffer = NULL; + ProtocolSet* set = new ProtocolSet; IPostBox* postBox = new PostBox(); + IPostBox* recvPostBox = new PostBox(); cout << "Server" << endl; Translator t; @@ -43,7 +48,7 @@ int main() ProtocolPlayerPos test; test.clientID = 0; test.ID = 5; - test.nrOfFloats = 16; + test.nrOfFloats = 10; test.matrix = new float[test.nrOfFloats]; for(int i = 0; i < (int)test.nrOfFloats; i++) @@ -51,7 +56,7 @@ int main() test.matrix[i] = (float)i; } - t.Pack(test, recvBuffer); + t.Pack(test, sendBuffer); WinTimer timer; @@ -59,14 +64,13 @@ int main() int client = -1; while(1) { - client = -1; - postBox->FetchMessage(client); - if(client != -1) + //Fetch new clients from the postbox + if(postBox->FetchMessage(client)) { cout << "Client connected: " << client << endl; - clients.push_back(new ThreadedClient(client)); + clients.push_back(new ThreadedClient(recvPostBox, client)); - clients.at(clients.size()-1)->Send(&recvBuffer); + clients.at(clients.size()-1)->Send(&sendBuffer); } //Send a message every 1 secounds to all clients. @@ -76,51 +80,52 @@ int main() timer.reset(); for(int i = 0; i < (int)clients.size(); i++) { - clients.at(i)->Send(&recvBuffer); + clients.at(i)->Send(&sendBuffer); } } - Sleep(100); + + //Fetch messages + if(recvPostBox->FetchMessage(recvBuffer)) + { + t.Unpack(set, *recvBuffer); + delete recvBuffer; + + PrintOutMessage(set); + set->Release(); + } + + Sleep(1); } listener.Shutdown(); - /* - ProtocolSet* set = new ProtocolSet; - - client1.Send(recvBuffer); - - while(1) - { - client1.Recv(recvBuffer); - - t.Unpack(set, recvBuffer); - cout << set->Protocol.pTest->clientID << ' ' << set->Protocol.pTest->packageType << ' ' << set->Protocol.pTest->size << endl; - cout << "Client1: " << set->Protocol.pTest->textMessage << endl; - for(int i = 0; i < (int)set->Protocol.pTest->numOfFloats; i++) - { - cout << set->Protocol.pTest->f[i] << ' '; - } - cout << endl; - set->Release(); - client2.Send(recvBuffer); - - client2.Recv(recvBuffer); - - t.Unpack(set, recvBuffer); - cout << set->Protocol.pTest->clientID << ' ' << set->Protocol.pTest->packageType << ' ' << set->Protocol.pTest->size << endl; - cout << "Client2: " << set->Protocol.pTest->textMessage << endl; - for(int i = 0; i < (int)set->Protocol.pTest->numOfFloats; i++) - { - cout << set->Protocol.pTest->f[i] << ' '; - } - cout << endl; - set->Release(); - client1.Send(recvBuffer); - } - - - ShutdownWinSock(); - delete set; - */ system("pause"); + + delete postBox; return 0; } + +void PrintOutMessage(ProtocolSet* set) +{ + switch(set->type) + { + case PackageType_header: + break; + case PackageType_test: + cout <<"Client 2: " << set->Protocol.pTest->textMessage <Protocol.pTest->numOfFloats; i++) + { + cout << set->Protocol.pTest->f[i] << ' ' ; + } + cout << endl; + break; + + case PackageType_player_pos: + cout << "ID " << set->Protocol.pPlayerPos->ID << endl; + for(int i = 0; i < (int)set->Protocol.pPlayerPos->nrOfFloats; i++) + { + cout << set->Protocol.pPlayerPos->matrix[i] << ' '; + } + cout << endl; + break; + } +} \ No newline at end of file From 79cf9df1114e266e4b2887319363d40830768d73 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Wed, 4 Dec 2013 12:40:49 +0100 Subject: [PATCH 07/17] Network - changed from & to smartpoints --- Code/Misc/ThreadSafeQueue.h | 50 ++++++++----------- .../NetworkDependencies/Connection.cpp | 13 ++--- Code/Network/NetworkDependencies/Connection.h | 4 +- .../Network/NetworkDependencies/IConnection.h | 6 ++- Code/Network/NetworkDependencies/ITranslate.h | 6 ++- Code/Network/NetworkDependencies/Listener.cpp | 7 +-- Code/Network/NetworkDependencies/Listener.h | 5 +- Code/Network/NetworkDependencies/PostBox.h | 3 +- .../NetworkDependencies/ThreadedClient.cpp | 25 ++++------ .../NetworkDependencies/ThreadedClient.h | 11 ++-- .../NetworkDependencies/Translator.cpp | 14 +++--- Code/Network/NetworkDependencies/Translator.h | 4 +- .../OysterNetworkClient/ClientMain.cpp | 12 ++--- .../OysterNetworkServer/ServerMain.cpp | 27 +++++----- 14 files changed, 93 insertions(+), 94 deletions(-) diff --git a/Code/Misc/ThreadSafeQueue.h b/Code/Misc/ThreadSafeQueue.h index 19775f55..2e10b74c 100644 --- a/Code/Misc/ThreadSafeQueue.h +++ b/Code/Misc/ThreadSafeQueue.h @@ -118,62 +118,53 @@ namespace Oyster Type ThreadSafeQueue::Pop() { mutex.LockMutex(); - if(this->front != NULL) - { - Type item = this->front->item; - Node *destroyer = this->front; - this->front = front->next; - delete destroyer; - this->nrOfNodes--; + Type item = this->front->item; + Node *destroyer = this->front; + this->front = front->next; + + delete destroyer; + this->nrOfNodes--; - if(nrOfNodes == 0) - { - this->front = NULL; - this->back = NULL; - } - mutex.UnlockMutex(); - return item; + if(nrOfNodes == 0) + { + this->front = NULL; + this->back = NULL; } mutex.UnlockMutex(); - - return NULL; + return item; } template < typename Type > Type ThreadSafeQueue::Front() { mutex.LockMutex(); - if(front != NULL) - { - mutex.UnlockMutex(); - return this->front->item; - } + + return this->front->item; + mutex.UnlockMutex(); - return NULL; } template < typename Type > Type ThreadSafeQueue::Back() { mutex.LockMutex(); - if(back != NULL) - { - return this->back->item; - } + + return this->back->item; + mutex.UnlockMutex(); - return NULL; } template < typename Type > int ThreadSafeQueue::Size() { - //? behövs denna låsas? mutex.LockMutex(); + return this->nrOfNodes; + mutex.UnlockMutex(); } @@ -181,7 +172,7 @@ namespace Oyster bool ThreadSafeQueue::IsEmpty() { mutex.LockMutex(); - if(nrOfNodes == 0 && this->front == NULL) + if(nrOfNodes == 0 || this->front == NULL) { mutex.UnlockMutex(); return true; @@ -191,6 +182,7 @@ namespace Oyster { mutex.UnlockMutex(); } + return false; } diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 19556bbd..a4d6dcdc 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -79,11 +79,11 @@ int Connection::Disconnect() return WSAGetLastError(); } -int Connection::Send(OysterByte& bytes) +int Connection::Send(Utility::DynamicMemory::SmartPointer &bytes) { int nBytes; - nBytes = send(this->socket, bytes, bytes.GetSize(), 0); + nBytes = send(this->socket, *bytes, bytes->GetSize(), 0); if(nBytes == SOCKET_ERROR) { return WSAGetLastError(); @@ -92,19 +92,20 @@ int Connection::Send(OysterByte& bytes) return 0; } -int Connection::Recieve(OysterByte& bytes) +int Connection::Recieve(Utility::DynamicMemory::SmartPointer &bytes) { int nBytes; - bytes.Resize(1000); - nBytes = recv(this->socket, bytes, 500, 0); + bytes.Get()->Resize(1000); + bytes->Resize(1000); + nBytes = recv(this->socket, *bytes , 500, 0); if(nBytes == SOCKET_ERROR) { return WSAGetLastError(); } else { - bytes.SetSize(nBytes); + bytes->SetSize(nBytes); } std::cout << "Size of the recieved data: " << nBytes << " bytes" << std::endl; diff --git a/Code/Network/NetworkDependencies/Connection.h b/Code/Network/NetworkDependencies/Connection.h index 27933abf..a0c6913b 100644 --- a/Code/Network/NetworkDependencies/Connection.h +++ b/Code/Network/NetworkDependencies/Connection.h @@ -23,8 +23,8 @@ namespace Oyster virtual int InitiateServer( unsigned short port ); virtual int InitiateClient(); - virtual int Send( OysterByte& bytes ); - virtual int Recieve( OysterByte& bytes ); + virtual int Send( Utility::DynamicMemory::SmartPointer &bytes ); + virtual int Recieve( Utility::DynamicMemory::SmartPointer &bytes ); virtual int Disconnect(); virtual int Connect( unsigned short port , const char serverName[] ); diff --git a/Code/Network/NetworkDependencies/IConnection.h b/Code/Network/NetworkDependencies/IConnection.h index 5f88932b..ecfe3869 100644 --- a/Code/Network/NetworkDependencies/IConnection.h +++ b/Code/Network/NetworkDependencies/IConnection.h @@ -5,6 +5,8 @@ // Created by Sam Svensson 2013 // ////////////////////////////////// +#include "../../Misc/Utilities.h" + namespace Oyster { namespace Network @@ -17,8 +19,8 @@ namespace Oyster //sends and recieve functions with bytearrays, //will send to the users connection via socket - virtual int Send( OysterByte& bytes ) = 0; - virtual int Recieve( OysterByte& bytes) = 0; + virtual int Send( Utility::DynamicMemory::SmartPointer &bytes ) = 0; + virtual int Recieve( Utility::DynamicMemory::SmartPointer &bytes) = 0; //initiates sockets and address for server and client virtual int InitiateServer( unsigned short port ) { return false; }; diff --git a/Code/Network/NetworkDependencies/ITranslate.h b/Code/Network/NetworkDependencies/ITranslate.h index 80edc8b1..77ceaa0f 100644 --- a/Code/Network/NetworkDependencies/ITranslate.h +++ b/Code/Network/NetworkDependencies/ITranslate.h @@ -5,6 +5,8 @@ // Created by Sam Svensson 2013 // ////////////////////////////////// +#include "../../Misc/Utilities.h" + namespace Oyster { namespace Network @@ -15,8 +17,8 @@ namespace Oyster public: //packs and unpacks packages for sending or recieving over the connection - virtual void Pack (Protocols::ProtocolHeader &header, OysterByte& bytes) = 0; - virtual void Unpack (Protocols::ProtocolSet* set, OysterByte& bytes ) = 0; + virtual void Pack (Protocols::ProtocolHeader &header, Utility::DynamicMemory::SmartPointer &bytes) = 0; + virtual void Unpack (Protocols::ProtocolSet* set, Utility::DynamicMemory::SmartPointer &bytes ) = 0; }; } diff --git a/Code/Network/NetworkDependencies/Listener.cpp b/Code/Network/NetworkDependencies/Listener.cpp index 05616aec..bebf4563 100644 --- a/Code/Network/NetworkDependencies/Listener.cpp +++ b/Code/Network/NetworkDependencies/Listener.cpp @@ -1,6 +1,7 @@ #include "Listener.h" using namespace Oyster::Network::Server; +using namespace Utility::DynamicMemory; Listener::Listener() { @@ -31,7 +32,7 @@ void Listener::Shutdown() thread.Stop(); } -void Listener::SetPostBox(Oyster::Network::IPostBox* postBox) +void Listener::SetPostBox(Oyster::Network::IPostBox>* postBox) { mutex.LockMutex(); this->postBox = postBox; @@ -40,8 +41,8 @@ void Listener::SetPostBox(Oyster::Network::IPostBox* postBox) int Listener::Accept() { - int clientSocket = 0; - clientSocket = connection->Listen(); + SmartPointer clientSocket = SmartPointer(new int()); + *clientSocket = connection->Listen(); mutex.LockMutex(); postBox->PostMessage(clientSocket); diff --git a/Code/Network/NetworkDependencies/Listener.h b/Code/Network/NetworkDependencies/Listener.h index 469e30c6..b9fdab21 100644 --- a/Code/Network/NetworkDependencies/Listener.h +++ b/Code/Network/NetworkDependencies/Listener.h @@ -9,6 +9,7 @@ #include "../NetworkDependencies/Connection.h" #include "../../Misc/Thread/OysterThread.h" #include "../../Misc/Thread/OysterMutex.h" +#include "../../Misc/Utilities.h" #include "IPostBox.h" namespace Oyster @@ -26,7 +27,7 @@ namespace Oyster bool Init(unsigned int port); void Shutdown(); - void SetPostBox(IPostBox* postBox); + void SetPostBox(IPostBox>* postBox); private: //Thread functions @@ -43,7 +44,7 @@ namespace Oyster ::Oyster::Thread::OysterThread thread; OysterMutex mutex; - IPostBox* postBox; + IPostBox>* postBox; }; } diff --git a/Code/Network/NetworkDependencies/PostBox.h b/Code/Network/NetworkDependencies/PostBox.h index 960b6f34..ca4d03c8 100644 --- a/Code/Network/NetworkDependencies/PostBox.h +++ b/Code/Network/NetworkDependencies/PostBox.h @@ -53,8 +53,7 @@ namespace Oyster { if(IsFull()) { - message = messages.Front(); - messages.Pop(); + message = messages.Pop(); return true; } return false; diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp index dafe70b8..57154f70 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.cpp +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -3,18 +3,19 @@ #include using namespace Oyster::Network; using namespace Oyster::Thread; +using namespace Utility::DynamicMemory; ThreadedClient::ThreadedClient() { this->connection = new Connection(); - this->sendPostBox = new PostBox(); + this->sendPostBox = new PostBox>(); this->recvPostBox = NULL; } ThreadedClient::ThreadedClient(unsigned int socket) { this->connection = new Connection(socket); - this->sendPostBox = new PostBox(); + this->sendPostBox = new PostBox>(); this->recvPostBox = NULL; connection->SetBlockingMode(false); @@ -22,10 +23,10 @@ ThreadedClient::ThreadedClient(unsigned int socket) thread.Create(this, true); } -ThreadedClient::ThreadedClient(IPostBox* postBox, unsigned int socket) +ThreadedClient::ThreadedClient(IPostBox>* postBox, unsigned int socket) { this->connection = new Connection(socket); - this->sendPostBox = new PostBox; + this->sendPostBox = new PostBox>; this->recvPostBox = postBox; connection->SetBlockingMode(false); @@ -47,7 +48,7 @@ ThreadedClient::~ThreadedClient() } } -int ThreadedClient::Send(OysterByte* byte) +int ThreadedClient::Send(SmartPointer &byte) { mutex.LockMutex(); this->sendPostBox->PostMessage(byte); @@ -61,9 +62,9 @@ int ThreadedClient::Send() mutex.LockMutex(); if(sendPostBox->IsFull()) { - OysterByte *temp = NULL; + SmartPointer temp = NULL; sendPostBox->FetchMessage(temp); - errorCode = this->connection->Send(*temp); + errorCode = this->connection->Send(temp); } mutex.UnlockMutex(); @@ -74,8 +75,8 @@ int ThreadedClient::Recv() { int errorCode = 0; - OysterByte *temp = new OysterByte(); - errorCode = this->connection->Recieve(*temp); + SmartPointer temp = SmartPointer(new OysterByte()); + errorCode = this->connection->Recieve(temp); if(errorCode == 0) { @@ -83,10 +84,6 @@ int ThreadedClient::Recv() recvPostBox->PostMessage(temp); mutex.UnlockMutex(); } - else - { - delete temp; - } return errorCode; } @@ -137,7 +134,7 @@ int ThreadedClient::Connect(unsigned short port, const char serverName[]) return 0; } -void ThreadedClient::setRecvPostBox(IPostBox* postBox) +void ThreadedClient::setRecvPostBox(IPostBox> *postBox) { this->mutex.LockMutex(); this->recvPostBox = postBox; diff --git a/Code/Network/NetworkDependencies/ThreadedClient.h b/Code/Network/NetworkDependencies/ThreadedClient.h index dbf99347..2808f351 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.h +++ b/Code/Network/NetworkDependencies/ThreadedClient.h @@ -10,6 +10,7 @@ #include "../NetworkDependencies/PostBox.h" #include "../../Misc/Thread/OysterThread.h" #include "../../Misc/Thread/OysterMutex.h" +#include "../../Misc/Utilities.h" namespace Oyster { @@ -20,14 +21,14 @@ namespace Oyster public: ThreadedClient(); ThreadedClient(unsigned int socket); - ThreadedClient(IPostBox* postBox, unsigned int socket); + ThreadedClient(IPostBox> *postBox, unsigned int socket); virtual ~ThreadedClient(); - int Send(OysterByte* byte); + int Send(Utility::DynamicMemory::SmartPointer< OysterByte > &byte); int Connect(unsigned short port, const char serverName[]); - void setRecvPostBox(IPostBox* postBox); + void setRecvPostBox(IPostBox< Utility::DynamicMemory::SmartPointer< OysterByte >> *postBox); private: virtual int Send(); @@ -39,8 +40,8 @@ namespace Oyster private: Connection* connection; - IPostBox* sendPostBox; - IPostBox* recvPostBox; + IPostBox> *sendPostBox; + IPostBox> *recvPostBox; Oyster::Thread::OysterThread thread; OysterMutex mutex; diff --git a/Code/Network/NetworkDependencies/Translator.cpp b/Code/Network/NetworkDependencies/Translator.cpp index 746b00f2..94f66d62 100644 --- a/Code/Network/NetworkDependencies/Translator.cpp +++ b/Code/Network/NetworkDependencies/Translator.cpp @@ -4,7 +4,7 @@ using namespace Oyster::Network; using namespace ::Protocols; using namespace ::Messages; -void Translator::Pack( ProtocolHeader &header, OysterByte& bytes ) +void Translator::Pack( ProtocolHeader &header, Utility::DynamicMemory::SmartPointer &bytes ) { MessageHeader *message = NULL; @@ -25,19 +25,19 @@ void Translator::Pack( ProtocolHeader &header, OysterByte& bytes ) if(message != NULL) { - message->Pack(header, bytes); + message->Pack(header, *bytes); delete message; message = NULL; } } -void Translator::Unpack(ProtocolSet* set, OysterByte& bytes ) +void Translator::Unpack(ProtocolSet* set, Utility::DynamicMemory::SmartPointer &bytes) { ProtocolHeader *header = new ProtocolHeader(); MessageHeader *message = new MessageHeader(); - message->Unpack(bytes, *header); + message->Unpack(*bytes, *header); delete message; message = NULL; @@ -48,19 +48,19 @@ void Translator::Unpack(ProtocolSet* set, OysterByte& bytes ) case PackageType_header: message = new MessageHeader(); set->Protocol.pHeader = new ProtocolHeader; - message->Unpack(bytes, *set->Protocol.pHeader); + message->Unpack(*bytes, *set->Protocol.pHeader); break; case PackageType_test: message = new MessageTest(); set->Protocol.pTest = new ProtocolTest; - message->Unpack(bytes, *set->Protocol.pTest); + message->Unpack(*bytes, *set->Protocol.pTest); break; case PackageType_player_pos: message = new MessagePlayerPos(); set->Protocol.pPlayerPos = new ProtocolPlayerPos; - message->Unpack(bytes, *set->Protocol.pPlayerPos); + message->Unpack(*bytes, *set->Protocol.pPlayerPos); break; } diff --git a/Code/Network/NetworkDependencies/Translator.h b/Code/Network/NetworkDependencies/Translator.h index 56459f72..94c88457 100644 --- a/Code/Network/NetworkDependencies/Translator.h +++ b/Code/Network/NetworkDependencies/Translator.h @@ -20,8 +20,8 @@ namespace Oyster Translator () { }; ~Translator() { }; - void Pack (Protocols::ProtocolHeader &header, OysterByte& bytes ); - void Unpack (Protocols::ProtocolSet* set, OysterByte& bytes ); + void Pack (Protocols::ProtocolHeader &header, Utility::DynamicMemory::SmartPointer &bytes ); + void Unpack (Protocols::ProtocolSet* set, Utility::DynamicMemory::SmartPointer &bytes ); private: diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index 45861c96..5a48598c 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -16,6 +16,7 @@ using namespace std; using namespace Oyster::Network::Protocols; using namespace Oyster::Network; using namespace Utility; +using namespace Utility::DynamicMemory; void chat(ThreadedClient &client); void PrintOutMessage(ProtocolSet* set); @@ -54,12 +55,12 @@ int main() void chat(ThreadedClient &client) { Oyster::Network::Translator *t = new Oyster::Network::Translator(); - IPostBox* postBox = new PostBox; + IPostBox< SmartPointer> *postBox = new PostBox< SmartPointer>; client.setRecvPostBox(postBox); - Oyster::Network::OysterByte* msgRecv = NULL; - Oyster::Network::OysterByte* msgSend = new OysterByte(); + SmartPointer msgRecv = NULL; + SmartPointer msgSend = SmartPointer(new OysterByte()); ProtocolSet* set = new ProtocolSet; ProtocolPlayerPos test; @@ -72,7 +73,7 @@ void chat(ThreadedClient &client) test.matrix[i] = temp; temp++; } - t->Pack(test, *msgSend); + t->Pack(test, msgSend); WinTimer timer; @@ -81,7 +82,7 @@ void chat(ThreadedClient &client) //Fetch new messages from the postbox if(postBox->FetchMessage(msgRecv)) { - t->Unpack(set, *msgRecv); + t->Unpack(set, msgRecv); delete msgRecv; PrintOutMessage(set); @@ -97,7 +98,6 @@ void chat(ThreadedClient &client) } } - delete msgSend; delete postBox; delete t; delete set; diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 95a07641..8e416f4e 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -9,6 +9,8 @@ #include "../NetworkDependencies/OysterByte.h" #include "../NetworkDependencies/PostBox.h" #include "../../Misc/WinTimer.h" +#include "../../Misc/Utilities.h" +#include "../../Misc/Utilities-Impl.h" #pragma comment(lib, "ws2_32.lib") @@ -17,20 +19,21 @@ using namespace Oyster::Network::Server; using namespace Oyster::Network; using namespace ::Protocols; using namespace Utility; +using namespace ::Utility::DynamicMemory; void PrintOutMessage(ProtocolSet* set); int main() -{ - OysterByte sendBuffer; - OysterByte* recvBuffer = NULL; +{ + SmartPointer sendBuffer = SmartPointer(new OysterByte); + SmartPointer recvBuffer = NULL; ProtocolSet* set = new ProtocolSet; - IPostBox* postBox = new PostBox(); - IPostBox* recvPostBox = new PostBox(); + IPostBox> *postBox = new PostBox>(); + IPostBox> *recvPostBox = new PostBox>(); cout << "Server" << endl; Translator t; - int errorCode; + int errorCode = 0; if(!InitWinSock()) { @@ -61,16 +64,16 @@ int main() WinTimer timer; vector clients; - int client = -1; + SmartPointer client = SmartPointer(); while(1) { //Fetch new clients from the postbox if(postBox->FetchMessage(client)) { - cout << "Client connected: " << client << endl; - clients.push_back(new ThreadedClient(recvPostBox, client)); + cout << "Client connected: " << *client << endl; + clients.push_back(new ThreadedClient(recvPostBox, *client)); - clients.at(clients.size()-1)->Send(&sendBuffer); + clients.at(clients.size()-1)->Send(sendBuffer); } //Send a message every 1 secounds to all clients. @@ -80,14 +83,14 @@ int main() timer.reset(); for(int i = 0; i < (int)clients.size(); i++) { - clients.at(i)->Send(&sendBuffer); + clients.at(i)->Send(sendBuffer); } } //Fetch messages if(recvPostBox->FetchMessage(recvBuffer)) { - t.Unpack(set, *recvBuffer); + t.Unpack(set, recvBuffer); delete recvBuffer; PrintOutMessage(set); From f0dff0b728df61dcf779476defa35972f4c3e6f3 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 4 Dec 2013 12:41:25 +0100 Subject: [PATCH 08/17] Network - Starting to implement correct shutdown connection. --- .../NetworkDependencies/Connection.cpp | 20 +++++++++++++++++++ Code/Network/NetworkDependencies/Connection.h | 7 +++++-- .../OysterNetworkServer/ServerMain.cpp | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 19556bbd..48767811 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -7,6 +7,20 @@ using namespace Oyster::Network; +Connection::Connection() +{ + this->socket = 0; + bool stillSending = false; + bool closed = true; +} + +Connection::Connection(int socket) +{ + this->socket = socket; + bool stillSending = false; + bool closed = true; +} + Connection::~Connection() { closesocket( this->socket ); @@ -30,6 +44,9 @@ int Connection::Connect(unsigned short port , const char serverName[]) return WSAGetLastError(); } + closed = false; + stillSending = true; + //connection succesfull! return 0; } @@ -63,6 +80,9 @@ int Connection::InitiateServer(unsigned short port) return errorCode; } + closed = false; + stillSending = true; + //Server started! return 0; } diff --git a/Code/Network/NetworkDependencies/Connection.h b/Code/Network/NetworkDependencies/Connection.h index 27933abf..09d8caea 100644 --- a/Code/Network/NetworkDependencies/Connection.h +++ b/Code/Network/NetworkDependencies/Connection.h @@ -16,8 +16,8 @@ namespace Oyster { public: - Connection() { this->socket = 0; }; - Connection( int socket ) { this->socket = socket; }; + Connection(); + Connection( int socket ); virtual ~Connection(); virtual int InitiateServer( unsigned short port ); @@ -39,6 +39,9 @@ namespace Oyster int socket; + bool stillSending; + bool closed; + }; } } diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 95a07641..74584b27 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -120,7 +120,7 @@ void PrintOutMessage(ProtocolSet* set) break; case PackageType_player_pos: - cout << "ID " << set->Protocol.pPlayerPos->ID << endl; + //cout << "ID " << set->Protocol.pPlayerPos->ID << endl; for(int i = 0; i < (int)set->Protocol.pPlayerPos->nrOfFloats; i++) { cout << set->Protocol.pPlayerPos->matrix[i] << ' '; From df1594a43ba4814ccc999599b9095e1981f80c41 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 4 Dec 2013 14:58:15 +0100 Subject: [PATCH 09/17] Network - Fixed small errors --- .../NetworkDependencies/Connection.cpp | 3 +- Code/Network/NetworkDependencies/Listener.cpp | 9 ++++-- .../NetworkDependencies/OysterByte.cpp | 28 +++++++++++++++++++ Code/Network/NetworkDependencies/OysterByte.h | 3 ++ Code/Network/NetworkDependencies/PostBox.h | 2 +- .../NetworkDependencies/ThreadedClient.cpp | 4 +-- .../OysterNetworkClient/ClientMain.cpp | 3 +- .../OysterNetworkServer/ServerMain.cpp | 7 +++-- 8 files changed, 47 insertions(+), 12 deletions(-) diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 169827ba..299f60d3 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -116,7 +116,6 @@ int Connection::Recieve(Utility::DynamicMemory::SmartPointer &bytes) { int nBytes; - bytes.Get()->Resize(1000); bytes->Resize(1000); nBytes = recv(this->socket, *bytes , 500, 0); if(nBytes == SOCKET_ERROR) @@ -138,7 +137,7 @@ int Connection::Listen() int clientSocket; if((clientSocket = accept(this->socket, NULL, NULL)) == INVALID_SOCKET) { - return WSAGetLastError(); + return INVALID_SOCKET;//WSAGetLastError(); } return clientSocket; diff --git a/Code/Network/NetworkDependencies/Listener.cpp b/Code/Network/NetworkDependencies/Listener.cpp index bebf4563..f00c282a 100644 --- a/Code/Network/NetworkDependencies/Listener.cpp +++ b/Code/Network/NetworkDependencies/Listener.cpp @@ -44,9 +44,12 @@ int Listener::Accept() SmartPointer clientSocket = SmartPointer(new int()); *clientSocket = connection->Listen(); - mutex.LockMutex(); - postBox->PostMessage(clientSocket); - mutex.UnlockMutex(); + if(*clientSocket != -1) + { + mutex.LockMutex(); + postBox->PostMessage(clientSocket); + mutex.UnlockMutex(); + } return clientSocket; } diff --git a/Code/Network/NetworkDependencies/OysterByte.cpp b/Code/Network/NetworkDependencies/OysterByte.cpp index 8df493f1..0ae7bf96 100644 --- a/Code/Network/NetworkDependencies/OysterByte.cpp +++ b/Code/Network/NetworkDependencies/OysterByte.cpp @@ -16,6 +16,19 @@ OysterByte::OysterByte(int cap) byteArray = new unsigned char[capacity]; } +OysterByte::OysterByte(const OysterByte& obj) +{ + delete[] this->byteArray; + this->byteArray = new unsigned char[obj.capacity]; + + for(int i = 0; i < obj.size; i++) + { + this->byteArray[i] = obj.byteArray[i]; + } + this->size = obj.size; + this->capacity = obj.capacity; +} + OysterByte::~OysterByte() { delete[] byteArray; @@ -67,6 +80,21 @@ void OysterByte::SetSize(unsigned int size) this->size = size; } +OysterByte& OysterByte::operator =(const OysterByte& obj) +{ + delete[] this->byteArray; + this->byteArray = new unsigned char[obj.capacity]; + + for(int i = 0; i < obj.size; i++) + { + this->byteArray[i] = obj.byteArray[i]; + } + this->size = obj.size; + this->capacity = obj.capacity; + + return *this; +} + OysterByte::operator char*() { return (char*)byteArray; diff --git a/Code/Network/NetworkDependencies/OysterByte.h b/Code/Network/NetworkDependencies/OysterByte.h index 9a6bc75a..99629bfc 100644 --- a/Code/Network/NetworkDependencies/OysterByte.h +++ b/Code/Network/NetworkDependencies/OysterByte.h @@ -16,6 +16,7 @@ namespace Oyster public: OysterByte(); OysterByte(int cap); + OysterByte(const OysterByte& obj); virtual ~OysterByte(); void Clear(); //Resets size to 0 @@ -28,6 +29,8 @@ namespace Oyster void SetBytes(unsigned char* bytes); void SetSize(unsigned int size); //Only sets the private variable 'size' + OysterByte& operator =(const OysterByte& obj); + operator char*(); operator const char*(); operator unsigned char*(); diff --git a/Code/Network/NetworkDependencies/PostBox.h b/Code/Network/NetworkDependencies/PostBox.h index ca4d03c8..f6db2c44 100644 --- a/Code/Network/NetworkDependencies/PostBox.h +++ b/Code/Network/NetworkDependencies/PostBox.h @@ -53,7 +53,7 @@ namespace Oyster { if(IsFull()) { - message = messages.Pop(); + message = messages.Pop(); return true; } return false; diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp index 57154f70..64b8c098 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.cpp +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -74,8 +74,8 @@ int ThreadedClient::Send() int ThreadedClient::Recv() { int errorCode = 0; - - SmartPointer temp = SmartPointer(new OysterByte()); + + SmartPointer temp = new OysterByte(); errorCode = this->connection->Recieve(temp); if(errorCode == 0) diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index 5a48598c..2d2d428f 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -59,7 +59,7 @@ void chat(ThreadedClient &client) client.setRecvPostBox(postBox); - SmartPointer msgRecv = NULL; + SmartPointer msgRecv = SmartPointer(new OysterByte()); SmartPointer msgSend = SmartPointer(new OysterByte()); ProtocolSet* set = new ProtocolSet; @@ -83,7 +83,6 @@ void chat(ThreadedClient &client) if(postBox->FetchMessage(msgRecv)) { t->Unpack(set, msgRecv); - delete msgRecv; PrintOutMessage(set); set->Release(); diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 0e6c0751..14c28da5 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -26,7 +26,7 @@ void PrintOutMessage(ProtocolSet* set); int main() { SmartPointer sendBuffer = SmartPointer(new OysterByte); - SmartPointer recvBuffer = NULL; + SmartPointer recvBuffer = SmartPointer(new OysterByte()); ProtocolSet* set = new ProtocolSet; IPostBox> *postBox = new PostBox>(); IPostBox> *recvPostBox = new PostBox>(); @@ -91,7 +91,6 @@ int main() if(recvPostBox->FetchMessage(recvBuffer)) { t.Unpack(set, recvBuffer); - delete recvBuffer; PrintOutMessage(set); set->Release(); @@ -100,9 +99,13 @@ int main() Sleep(1); } listener.Shutdown(); + Sleep(1000); system("pause"); + for(int i = 0; i < clients.size(); i++) + delete clients.at(i); + delete postBox; return 0; } From cc793851affee55677993255a0fa38114547ac65 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Wed, 4 Dec 2013 14:56:44 +0100 Subject: [PATCH 10/17] Network- set blocking mode --- Code/Network/NetworkDependencies/ThreadedClient.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp index 64b8c098..2ad49553 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.cpp +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -10,6 +10,8 @@ ThreadedClient::ThreadedClient() this->connection = new Connection(); this->sendPostBox = new PostBox>(); this->recvPostBox = NULL; + + connection->SetBlockingMode(false); } ThreadedClient::ThreadedClient(unsigned int socket) From cb8fee92275e0b9c3c5a520f305ce235adb4e666 Mon Sep 17 00:00:00 2001 From: dean11 Date: Fri, 6 Dec 2013 10:00:58 +0100 Subject: [PATCH 11/17] NETWORK - Added network custom protocol --- .../NetworkProtocol/CustomNetProtocol.cpp | 296 ++++++++++++++++++ .../NetworkProtocol/CustomNetProtocol.h | 118 +++++++ .../NetworkProtocol/NetworkProtocol.vcxproj | 171 ++++++++++ 3 files changed, 585 insertions(+) create mode 100644 Code/Network/NetworkProtocol/CustomNetProtocol.cpp create mode 100644 Code/Network/NetworkProtocol/CustomNetProtocol.h create mode 100644 Code/Network/NetworkProtocol/NetworkProtocol.vcxproj diff --git a/Code/Network/NetworkProtocol/CustomNetProtocol.cpp b/Code/Network/NetworkProtocol/CustomNetProtocol.cpp new file mode 100644 index 00000000..ef9d3fc2 --- /dev/null +++ b/Code/Network/NetworkProtocol/CustomNetProtocol.cpp @@ -0,0 +1,296 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#include "CustomNetProtocol.h" +#include + +using namespace Network; + +enum NetContainerType +{ + NetContainer_Array, + NetContainer_Single, + NetContainer_UNKNOWN, +}; +struct NetAttributeArray +{ + NetAttributeContainer *value; + int count; + NetAttributeArray() + :value(0) + , count(0) + {} +}; +union NetAttributeData +{ + struct { NetAttributeContainer singleVal; }; + struct { NetAttributeArray arrayVal; }; +}; +struct NetDataValue +{ + NetContainerType containerType; + NetAttributeData attributeData; + NetDataValue() + { + //memset(&attributeData, 0, sizeof(NetAttributeData)); + containerType = NetContainer_UNKNOWN; + attributeData.singleVal.type = NetAttributeType_UNKNOWN; + } +}; + + + +struct CustomNetProtocol::PrivateData +{ + std::map attributes; + //DataValue *val; + //unsigned int size; + + PrivateData() + { + //val = new DataValue[_size]; + //size = _size; + } + ~PrivateData() + { + for (auto i = attributes.begin(); i != attributes.end(); i++) + { + RemoveAttribute(i->first); + } + } + void RemoveAttribute(int ID) + { + auto i = attributes.find(ID); + if(i == attributes.end()) return; + + if(i->second.containerType == NetContainer_Single) + { + switch (i->second.attributeData.singleVal.type) + { + case NetAttributeType_CharArray: + delete [] i->second.attributeData.singleVal.value.netCharPtr; + break; + } + } + else if(i->second.containerType == NetContainer_Array) + { + } + + } + + //Do network stuff +}; + + +CustomNetProtocol::CustomNetProtocol() +{ + this->privateData = new PrivateData(); +} +CustomNetProtocol::~CustomNetProtocol() +{ + delete this->privateData; +} +NetAttributeContainer* CustomNetProtocol::operator[](int ID) +{ + NetAttributeContainer *retVal = 0; + + if(this->privateData->attributes.find(ID) == this->privateData->attributes.end()) + return retVal; + + if(this->privateData->attributes[ID].containerType == NetContainer_Single) + retVal = &this->privateData->attributes[ID].attributeData.singleVal; + + if(this->privateData->attributes[ID].containerType == NetContainer_Array) + retVal = this->privateData->attributes[ID].attributeData.arrayVal.value; + + return retVal; +} + + +NetAttributeContainer* CustomNetProtocol::BuildValue(NetAttributeContainer val, short ID) +{ + if(val.type == NetAttributeType_UNKNOWN) return 0; + + this->privateData->RemoveAttribute(ID); + + this->privateData->attributes[ID].attributeData.singleVal = val; + + return &this->privateData->attributes[ID].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(NetAttributeValue value, NetAttributeType type, short ID) +{ + if(type == NetAttributeType_UNKNOWN) return 0; + + this->privateData->RemoveAttribute(ID); + + this->privateData->attributes[ID].attributeData.singleVal.value = value; + this->privateData->attributes[ID].attributeData.singleVal.type = type; + + return &this->privateData->attributes[ID].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const bool & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netBool = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Bool; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const char & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netChar = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Char; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const unsigned char & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netUChar = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_UnsignedChar; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const short & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netShort = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Short; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const unsigned short & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netUShort = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_UnsignedShort; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const int & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netInt = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Int; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const unsigned int & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netUInt = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_UnsignedInt; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const __int64 & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netInt64 = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Int64; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const unsigned __int64 & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netUInt64 = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_UnsignedInt64; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const float & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netFloat = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Float; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const double & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netDouble = attribute; + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Double; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const std::string & attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netCharPtr = _strdup(attribute.c_str()); + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_CharArray; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} +NetAttributeContainer* CustomNetProtocol::BuildValue(const char* attribute, short attributeId) +{ + this->privateData->RemoveAttribute(attributeId); + + this->privateData->attributes[attributeId].attributeData.singleVal.value.netCharPtr = _strdup(attribute); + this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_CharArray; + this->privateData->attributes[attributeId].containerType = NetContainer_Single; + + return &this->privateData->attributes[attributeId].attributeData.singleVal; +} + + +//void CustomNetProtocol::SetArrayValue(NetAttributeContainer attribute[], unsigned int attributeCount, int ID) +//{ +// if(this->privateData->attributes.find(ID) == this->privateData->attributes.end()) +// { +// this->privateData->attributes[ID] = NetDataValue(); +// } +// +// if(this->privateData->attributes[ID].containerType == NetContainer_UNKNOWN) +// this->privateData->attributes[ID].containerType = NetContainer_Array; +// +// this->privateData->attributes[ID].attributeData.arrayVal.value = attribute; +//} + +NetAttributeContainer& CustomNetProtocol::GetSingleValue(int attributeID) +{ + return this->privateData->attributes[attributeID].attributeData.singleVal; +} +//NetAttributeContainer* CustomNetProtocol::GetArrayValue(int attributeID) +//{ +// return this->privateData->attributes[attributeID].attributeData.arrayVal.value; +//} + + + + + + + + + + + + + diff --git a/Code/Network/NetworkProtocol/CustomNetProtocol.h b/Code/Network/NetworkProtocol/CustomNetProtocol.h new file mode 100644 index 00000000..2845250f --- /dev/null +++ b/Code/Network/NetworkProtocol/CustomNetProtocol.h @@ -0,0 +1,118 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#ifndef NETWORK_CUSTOM_NETWORK_PROTOCOL_H +#define NETWORK_CUSTOM_NETWORK_PROTOCOL_H + +#include + +#ifdef CUSTOM_NET_PROTOCOL_EXPORT + #define NET_PROTOCOL_EXPORT __declspec(dllexport) +#else + #define NET_PROTOCOL_EXPORT __declspec(dllimport) +#endif + +namespace Network +{ + extern "C" + { + enum NetAttributeType + { + NetAttributeType_Bool, + NetAttributeType_Char, + NetAttributeType_UnsignedChar, + NetAttributeType_Short, + NetAttributeType_UnsignedShort, + NetAttributeType_Int, + NetAttributeType_UnsignedInt, + NetAttributeType_Int64, + NetAttributeType_UnsignedInt64, + NetAttributeType_Float, + NetAttributeType_Double, + NetAttributeType_CharArray, + NetAttributeType_UNKNOWN, + }; + union NetAttributeValue + { + bool netBool; + char netChar; + unsigned char netUChar; + short netShort; + unsigned short netUShort; + int netInt; + unsigned int netUInt; + __int64 netInt64; + unsigned __int64 netUInt64; + float netFloat; + double netDouble; + char* netCharPtr; + + NetAttributeValue(){ memset(this, 0, sizeof(NetAttributeValue)); } + NetAttributeValue(bool v) : netBool (v) {} + NetAttributeValue(char v) : netChar (v) {} + NetAttributeValue(unsigned char v) : netUChar (v) {} + NetAttributeValue(short v) : netShort (v) {} + NetAttributeValue(unsigned short v) : netUShort (v) {} + NetAttributeValue(int v) : netInt (v) {} + NetAttributeValue(unsigned int v) : netUInt (v) {} + NetAttributeValue(__int64 v) : netInt64 (v) {} + NetAttributeValue(unsigned __int64 v) : netUInt64 (v) {} + NetAttributeValue(float v) : netFloat (v) {} + NetAttributeValue(double v) : netDouble (v) {} + NetAttributeValue(char* v) : netCharPtr(v) {} + }; + struct NetAttributeContainer + { + NetAttributeType type; + NetAttributeValue value; + NetAttributeContainer() { type = NetAttributeType_UNKNOWN; } + }; + class NET_PROTOCOL_EXPORT CustomNetProtocol + { + public: + CustomNetProtocol(); + ~CustomNetProtocol(); + + NetAttributeContainer* operator[](int ID); + + NetAttributeContainer* BuildValue(NetAttributeContainer value, short attributeId); + NetAttributeContainer* BuildValue(NetAttributeValue value, NetAttributeType type, short attributeId); + NetAttributeContainer* BuildValue(const bool & attribute, short attributeId); + NetAttributeContainer* BuildValue(const char & attribute, short attributeId); + NetAttributeContainer* BuildValue(const unsigned char & attribute, short attributeId); + NetAttributeContainer* BuildValue(const short & attribute, short attributeId); + NetAttributeContainer* BuildValue(const unsigned short & attribute, short attributeId); + NetAttributeContainer* BuildValue(const int & attribute, short attributeId); + NetAttributeContainer* BuildValue(const unsigned int & attribute, short attributeId); + NetAttributeContainer* BuildValue(const __int64 & attribute, short attributeId); + NetAttributeContainer* BuildValue(const unsigned __int64 & attribute, short attributeId); + NetAttributeContainer* BuildValue(const float & attribute, short attributeId); + NetAttributeContainer* BuildValue(const double & attribute, short attributeId); + NetAttributeContainer* BuildValue(const std::string & attribute, short attributeId); + NetAttributeContainer* BuildValue(const char * attribute, short attributeId); + + //void SetArrayValue(NetAttributeContainer attribute[], unsigned int attributeCount, int attributeId); + + NetAttributeContainer& GetSingleValue(int attributeID); + //NetAttributeContainer* GetArrayValue(int attributeID); + + private: + struct PrivateData; + PrivateData* privateData; + }; + + }//End extern "C" +} //End namespace Network +#endif // !NETWORK_CUSTOM_NETWORK_PROTOCOL_H + + + + + + + + + + + + diff --git a/Code/Network/NetworkProtocol/NetworkProtocol.vcxproj b/Code/Network/NetworkProtocol/NetworkProtocol.vcxproj new file mode 100644 index 00000000..36dddd75 --- /dev/null +++ b/Code/Network/NetworkProtocol/NetworkProtocol.vcxproj @@ -0,0 +1,171 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {460D625F-2AC9-4559-B809-0BA89CEAEDF4} + Win32Proj + NetworkProtocol + NetworkProtocol + + + + DynamicLibrary + true + v110 + Unicode + + + DynamicLibrary + true + v110 + Unicode + + + DynamicLibrary + false + v110 + true + Unicode + + + DynamicLibrary + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + true + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\Bin\DLL\ + $(ProjectName)_$(PlatformShortName)D + + + true + C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath) + C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath) + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\Bin\DLL\ + $(ProjectName)_$(PlatformShortName)D + + + false + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\Bin\DLL\ + $(ProjectName)_$(PlatformShortName) + + + false + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\Bin\DLL\ + $(ProjectName)_$(PlatformShortName) + + + + + + Level3 + Disabled + CUSTOM_NET_PROTOCOL_EXPORT;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + CUSTOM_NET_PROTOCOL_EXPORT;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + CUSTOM_NET_PROTOCOL_EXPORT;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + CUSTOM_NET_PROTOCOL_EXPORT;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file From 5465ccf51abede2960935b6d0c8a238cde27b845 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 6 Dec 2013 10:45:53 +0100 Subject: [PATCH 12/17] Network - Started implementing Server,client,session. --- .../NetworkDependencies/ThreadedClient.cpp | 16 ++++--- .../NetworkDependencies/ThreadedClient.h | 2 +- .../OysterNetworkClient/ClientMain.cpp | 4 +- Code/Network/OysterNetworkServer/IClient.h | 22 +++++++++ Code/Network/OysterNetworkServer/IServer.cpp | 45 +++++++++++++++++++ Code/Network/OysterNetworkServer/IServer.h | 34 ++++++++++++++ Code/Network/OysterNetworkServer/ISession.h | 34 ++++++++++++++ .../OysterNetworkServer.vcxproj | 6 +++ .../OysterNetworkServer.vcxproj.filters | 14 ++++++ .../OysterNetworkServer/ServerMain.cpp | 17 +++++-- 10 files changed, 180 insertions(+), 14 deletions(-) create mode 100644 Code/Network/OysterNetworkServer/IClient.h create mode 100644 Code/Network/OysterNetworkServer/IServer.cpp create mode 100644 Code/Network/OysterNetworkServer/IServer.h create mode 100644 Code/Network/OysterNetworkServer/ISession.h diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp index 64b8c098..0f3dcb54 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.cpp +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -48,10 +48,12 @@ ThreadedClient::~ThreadedClient() } } -int ThreadedClient::Send(SmartPointer &byte) +int ThreadedClient::Send(SmartPointer& byte) { + SmartPointer temp = new OysterByte(*byte); + mutex.LockMutex(); - this->sendPostBox->PostMessage(byte); + this->sendPostBox->PostMessage(temp); mutex.UnlockMutex(); return 0; } @@ -62,9 +64,9 @@ int ThreadedClient::Send() mutex.LockMutex(); if(sendPostBox->IsFull()) { - SmartPointer temp = NULL; - sendPostBox->FetchMessage(temp); - errorCode = this->connection->Send(temp); + //SmartPointer temp = NULL; + //sendPostBox->FetchMessage(temp); + //errorCode = this->connection->Send(temp); } mutex.UnlockMutex(); @@ -75,7 +77,7 @@ int ThreadedClient::Recv() { int errorCode = 0; - SmartPointer temp = new OysterByte(); + /*SmartPointer temp = new OysterByte(); errorCode = this->connection->Recieve(temp); if(errorCode == 0) @@ -84,7 +86,7 @@ int ThreadedClient::Recv() recvPostBox->PostMessage(temp); mutex.UnlockMutex(); } - + */ return errorCode; } diff --git a/Code/Network/NetworkDependencies/ThreadedClient.h b/Code/Network/NetworkDependencies/ThreadedClient.h index 2808f351..007f9338 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.h +++ b/Code/Network/NetworkDependencies/ThreadedClient.h @@ -24,7 +24,7 @@ namespace Oyster ThreadedClient(IPostBox> *postBox, unsigned int socket); virtual ~ThreadedClient(); - int Send(Utility::DynamicMemory::SmartPointer< OysterByte > &byte); + int Send(Utility::DynamicMemory::SmartPointer< OysterByte >& byte); int Connect(unsigned short port, const char serverName[]); diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index 2d2d428f..d436759e 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -59,8 +59,8 @@ void chat(ThreadedClient &client) client.setRecvPostBox(postBox); - SmartPointer msgRecv = SmartPointer(new OysterByte()); - SmartPointer msgSend = SmartPointer(new OysterByte()); + SmartPointer msgRecv = new OysterByte(); + SmartPointer msgSend = new OysterByte(); ProtocolSet* set = new ProtocolSet; ProtocolPlayerPos test; diff --git a/Code/Network/OysterNetworkServer/IClient.h b/Code/Network/OysterNetworkServer/IClient.h new file mode 100644 index 00000000..f7a115c3 --- /dev/null +++ b/Code/Network/OysterNetworkServer/IClient.h @@ -0,0 +1,22 @@ +#ifndef OYSTER_NETWORK_SERVER_I_CLIENT_H +#define OYSTER_NETWORK_SERVER_I_CLIENT_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +class IClient +{ +public: + virtual ~IClient() {} + + virtual void Disconnect() {}; + virtual bool IsConnected() {}; + + virtual void Send() {}; + +private: + +}; + +#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/IServer.cpp b/Code/Network/OysterNetworkServer/IServer.cpp new file mode 100644 index 00000000..17c50571 --- /dev/null +++ b/Code/Network/OysterNetworkServer/IServer.cpp @@ -0,0 +1,45 @@ +#include "IServer.h" + +IServer::IServer() +{ + +} + +IServer::~IServer() +{ + +} + +bool IServer::Init(INIT_DESC& initDesc) +{ + + return true; +} + +bool IServer::Start() +{ + + return true; +} + +bool IServer::Stop() +{ + + return true; +} + +bool IServer::Shutdown() +{ + + return true; +} + +void IServer::AddSession(ISession* session) +{ + +} + +void IServer::RemoveSession(ISession* session) +{ + +} \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/IServer.h b/Code/Network/OysterNetworkServer/IServer.h new file mode 100644 index 00000000..cdb1131a --- /dev/null +++ b/Code/Network/OysterNetworkServer/IServer.h @@ -0,0 +1,34 @@ +#ifndef OYSTER_NETWORK_SERVER_I_SERVER_H +#define OYSTER_NETWORK_SERVER_I_SERVER_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +class IServer +{ + class ISession; + +public: + struct INIT_DESC + { + + }; + + IServer(); + virtual ~IServer(); + + virtual bool Init(INIT_DESC& initDesc); + virtual bool Start(); + virtual bool Stop(); + virtual bool Shutdown(); + + virtual void AddSession(ISession* session); + virtual void RemoveSession(ISession* session); + +private: + + +}; + +#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/ISession.h b/Code/Network/OysterNetworkServer/ISession.h new file mode 100644 index 00000000..84ca05e0 --- /dev/null +++ b/Code/Network/OysterNetworkServer/ISession.h @@ -0,0 +1,34 @@ +#ifndef OYSTER_NETWORK_SERVER_I_SESSION_H +#define OYSTER_NETWORK_SERVER_I_SESSION_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +class ISession +{ + class IClient; +public: + struct INIT_DESC + { + + }; + + ISession(); + virtual ~ISession(); + + virtual bool Init(); + virtual bool Start(); + virtual bool Stop(); + virtual bool Shutdown(); + + virtual void SendToAll(); + + virtual void AddClient(IClient* client); + virtual void RemoveClient(IClient* client); + +private: +}; + + +#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj index d2268387..196da525 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj @@ -154,8 +154,14 @@ + + + + + + diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters index f8025a15..fc74d185 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters @@ -18,5 +18,19 @@ Source Files + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 14c28da5..f8c262de 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -12,6 +12,9 @@ #include "../../Misc/Utilities.h" #include "../../Misc/Utilities-Impl.h" +#include "IServer.h" +#include "ISession.h" + #pragma comment(lib, "ws2_32.lib") using namespace std; @@ -24,9 +27,15 @@ using namespace ::Utility::DynamicMemory; void PrintOutMessage(ProtocolSet* set); int main() -{ - SmartPointer sendBuffer = SmartPointer(new OysterByte); - SmartPointer recvBuffer = SmartPointer(new OysterByte()); +{ + IServer server; + IServer::INIT_DESC initDesc; + server.Init(initDesc); + + + //Old program + SmartPointer sendBuffer = new OysterByte; + SmartPointer recvBuffer = new OysterByte(); ProtocolSet* set = new ProtocolSet; IPostBox> *postBox = new PostBox>(); IPostBox> *recvPostBox = new PostBox>(); @@ -64,7 +73,7 @@ int main() WinTimer timer; vector clients; - SmartPointer client = SmartPointer(); + SmartPointer client = int(); while(1) { //Fetch new clients from the postbox From a79dc6115910709840bfc6d5d7d890ea603ddb38 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Sun, 8 Dec 2013 23:56:17 +0100 Subject: [PATCH 13/17] Network - Stuff --- Code/Misc/ThreadSafeQueue.h | 23 ++-- Code/Network/NetworkDependencies/IClient.h | 28 ----- Code/Network/NetworkDependencies/IListener.h | 1 + Code/Network/NetworkDependencies/Listener.cpp | 31 ++++- Code/Network/NetworkDependencies/Listener.h | 11 +- .../NetworkDependencies.vcxproj | 1 - .../NetworkDependencies.vcxproj.filters | 34 +++--- .../NetworkDependencies/ThreadedClient.cpp | 18 +-- .../NetworkDependencies/ThreadedClient.h | 13 +- .../OysterNetworkClient/ClientMain.cpp | 2 +- Code/Network/OysterNetworkServer/IClient.h | 7 +- Code/Network/OysterNetworkServer/IServer.cpp | 113 +++++++++++++++++- Code/Network/OysterNetworkServer/IServer.h | 48 +++++--- .../OysterNetworkServer/ServerMain.cpp | 35 ++++-- 14 files changed, 251 insertions(+), 114 deletions(-) delete mode 100644 Code/Network/NetworkDependencies/IClient.h diff --git a/Code/Misc/ThreadSafeQueue.h b/Code/Misc/ThreadSafeQueue.h index 2e10b74c..b26d35ff 100644 --- a/Code/Misc/ThreadSafeQueue.h +++ b/Code/Misc/ThreadSafeQueue.h @@ -94,9 +94,9 @@ namespace Oyster template < typename Type > void ThreadSafeQueue::Push(Type item) { + mutex.LockMutex(); Node *e = new Node(item); - mutex.LockMutex(); if(this->front != NULL) { this->back->next = e; @@ -140,32 +140,33 @@ namespace Oyster Type ThreadSafeQueue::Front() { mutex.LockMutex(); - - return this->front->item; - + Type temp = this->front->item; mutex.UnlockMutex(); - + + return temp; + } template < typename Type > Type ThreadSafeQueue::Back() { mutex.LockMutex(); - - return this->back->item; - + Type temp = this->back->item; mutex.UnlockMutex(); + return temp; + } template < typename Type > int ThreadSafeQueue::Size() { mutex.LockMutex(); - - return this->nrOfNodes; - + int size = this->nrOfNodes; mutex.UnlockMutex(); + + return size; + } template < typename Type > diff --git a/Code/Network/NetworkDependencies/IClient.h b/Code/Network/NetworkDependencies/IClient.h deleted file mode 100644 index bf044bae..00000000 --- a/Code/Network/NetworkDependencies/IClient.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef NETWORK_DEPENDENCIES_I_CLIENT_H -#define NETWORK_DEPENDENCIES_I_CLIENT_H - -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "../NetworkDependencies/Connection.h" -#include "../NetworkDependencies/OysterByte.h" - -namespace Oyster -{ - namespace Network - { - class IClient - { - - public: - virtual ~IClient() {}; - virtual int Send() = 0; - virtual int Recv() = 0; - - private: - - }; - } -} -#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/IListener.h b/Code/Network/NetworkDependencies/IListener.h index f08cfb27..f88f23ea 100644 --- a/Code/Network/NetworkDependencies/IListener.h +++ b/Code/Network/NetworkDependencies/IListener.h @@ -14,6 +14,7 @@ namespace Oyster class IListener { public: + virtual ~IListener() {} virtual bool Init(unsigned int port) = 0; virtual int Accept() = 0; diff --git a/Code/Network/NetworkDependencies/Listener.cpp b/Code/Network/NetworkDependencies/Listener.cpp index f00c282a..6a9fbeb5 100644 --- a/Code/Network/NetworkDependencies/Listener.cpp +++ b/Code/Network/NetworkDependencies/Listener.cpp @@ -8,6 +8,12 @@ Listener::Listener() connection = NULL; } +Listener::Listener(Oyster::Network::IPostBox>* postBox) +{ + connection = NULL; + this->postBox = postBox; +} + Listener::~Listener() { if(connection) @@ -16,10 +22,10 @@ Listener::~Listener() } } +//Starts the thread immediate bool Listener::Init(unsigned int port) { connection = new Connection(); - connection->InitiateServer(port); thread.Create(this, true); @@ -27,6 +33,26 @@ bool Listener::Init(unsigned int port) return true; } +bool Listener::Init(unsigned int port, bool start) +{ + connection = new Connection(); + connection->InitiateServer(port); + + thread.Create(this, start); + + return true; +} + +void Listener::Start() +{ + thread.Start(); +} + +void Listener::Stop() +{ + thread.Stop(); +} + void Listener::Shutdown() { thread.Stop(); @@ -61,13 +87,10 @@ bool Listener::DoWork() return true; } -#include void Listener::ThreadEntry() { - std::cout << "Thread started" << std::endl; } void Listener::ThreadExit() { - std::cout << "Thread stopped" << std::endl; } \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Listener.h b/Code/Network/NetworkDependencies/Listener.h index b9fdab21..16b884dd 100644 --- a/Code/Network/NetworkDependencies/Listener.h +++ b/Code/Network/NetworkDependencies/Listener.h @@ -6,11 +6,11 @@ ///////////////////////////////////// #include "IListener.h" -#include "../NetworkDependencies/Connection.h" +#include "Connection.h" +#include "IPostBox.h" #include "../../Misc/Thread/OysterThread.h" #include "../../Misc/Thread/OysterMutex.h" #include "../../Misc/Utilities.h" -#include "IPostBox.h" namespace Oyster { @@ -18,13 +18,18 @@ namespace Oyster { namespace Server { - class Listener : public ::Oyster::Thread::IThreadObject + class Listener : public IListener, public ::Oyster::Thread::IThreadObject { public: Listener(); + Listener(Oyster::Network::IPostBox>* postBox); ~Listener(); bool Init(unsigned int port); + bool Init(unsigned int port, bool start); + void Start(); + void Stop(); + void Shutdown(); void SetPostBox(IPostBox>* postBox); diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj index d320872f..ca48c730 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj @@ -165,7 +165,6 @@ - diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index 083f7a1d..9d10d4dc 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -2,38 +2,34 @@ + - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - + + + \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp index 4330e9f6..ba6b2c3b 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.cpp +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -1,4 +1,5 @@ #include "ThreadedClient.h" +#include "OysterByte.h" #include using namespace Oyster::Network; @@ -25,7 +26,7 @@ ThreadedClient::ThreadedClient(unsigned int socket) thread.Create(this, true); } -ThreadedClient::ThreadedClient(IPostBox>* postBox, unsigned int socket) +ThreadedClient::ThreadedClient(IPostBox>* postBox, unsigned int socket) { this->connection = new Connection(socket); this->sendPostBox = new PostBox>; @@ -57,29 +58,32 @@ int ThreadedClient::Send(SmartPointer& byte) mutex.LockMutex(); this->sendPostBox->PostMessage(temp); mutex.UnlockMutex(); + return 0; } int ThreadedClient::Send() { int errorCode = 0; + mutex.LockMutex(); if(sendPostBox->IsFull()) { - //SmartPointer temp = NULL; - //sendPostBox->FetchMessage(temp); - //errorCode = this->connection->Send(temp); + SmartPointer temp = new OysterByte; + sendPostBox->FetchMessage(temp); + errorCode = this->connection->Send(temp); } mutex.UnlockMutex(); + return errorCode; } int ThreadedClient::Recv() { int errorCode = 0; - - /*SmartPointer temp = new OysterByte(); + + SmartPointer temp = new OysterByte; errorCode = this->connection->Recieve(temp); if(errorCode == 0) @@ -88,7 +92,7 @@ int ThreadedClient::Recv() recvPostBox->PostMessage(temp); mutex.UnlockMutex(); } - */ + return errorCode; } diff --git a/Code/Network/NetworkDependencies/ThreadedClient.h b/Code/Network/NetworkDependencies/ThreadedClient.h index 007f9338..3d12ab6f 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.h +++ b/Code/Network/NetworkDependencies/ThreadedClient.h @@ -5,9 +5,9 @@ // Created by Sam Svensson 2013 // ////////////////////////////////// -#include "../NetworkDependencies/IClient.h" #include "../../Misc/Thread/IThreadObject.h" -#include "../NetworkDependencies/PostBox.h" +#include "PostBox.h" +#include "Connection.h" #include "../../Misc/Thread/OysterThread.h" #include "../../Misc/Thread/OysterMutex.h" #include "../../Misc/Utilities.h" @@ -16,19 +16,20 @@ namespace Oyster { namespace Network { - class ThreadedClient : public IClient, public Thread::IThreadObject + class OysterByte; + class ThreadedClient : public Thread::IThreadObject { public: ThreadedClient(); ThreadedClient(unsigned int socket); - ThreadedClient(IPostBox> *postBox, unsigned int socket); + ThreadedClient(IPostBox> *postBox, unsigned int socket); virtual ~ThreadedClient(); - int Send(Utility::DynamicMemory::SmartPointer< OysterByte >& byte); + int Send(Utility::DynamicMemory::SmartPointer& byte); int Connect(unsigned short port, const char serverName[]); - void setRecvPostBox(IPostBox< Utility::DynamicMemory::SmartPointer< OysterByte >> *postBox); + void setRecvPostBox(IPostBox> *postBox); private: virtual int Send(); diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index d436759e..95f966b8 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -84,7 +84,7 @@ void chat(ThreadedClient &client) { t->Unpack(set, msgRecv); - PrintOutMessage(set); + //PrintOutMessage(set); set->Release(); } diff --git a/Code/Network/OysterNetworkServer/IClient.h b/Code/Network/OysterNetworkServer/IClient.h index f7a115c3..5b7fafe9 100644 --- a/Code/Network/OysterNetworkServer/IClient.h +++ b/Code/Network/OysterNetworkServer/IClient.h @@ -8,12 +8,13 @@ class IClient { public: + IClient() {} virtual ~IClient() {} - virtual void Disconnect() {}; - virtual bool IsConnected() {}; + virtual void Disconnect() {} + virtual bool IsConnected() {return true;} - virtual void Send() {}; + virtual void Send() {} private: diff --git a/Code/Network/OysterNetworkServer/IServer.cpp b/Code/Network/OysterNetworkServer/IServer.cpp index 17c50571..82d5a155 100644 --- a/Code/Network/OysterNetworkServer/IServer.cpp +++ b/Code/Network/OysterNetworkServer/IServer.cpp @@ -1,35 +1,139 @@ #include "IServer.h" +#include "../NetworkDependencies/Listener.h" +#include "IClient.h" +#include "../NetworkDependencies/PostBox.h" +#include "../../Misc/Utilities.h" + +using namespace Oyster::Network; +using namespace ::Server; +using namespace Utility::DynamicMemory; + +/************************************* + PrivateData +*************************************/ + +struct IServer::PrivateData +{ + PrivateData(); + ~PrivateData(); + + bool Init(INIT_DESC& initDesc); + bool Start(); + bool Stop(); + bool Shutdown(); + + // + IListener* listener; + INIT_DESC initDesc; + bool started; + + IPostBox> *postBox; +}; + +IServer::PrivateData::PrivateData() +{ + listener = 0; + started = false; + postBox = new PostBox>(); +} + +IServer::PrivateData::~PrivateData() +{ + Shutdown(); +} + +bool IServer::PrivateData::Init(INIT_DESC& initDesc) +{ + //Check if it's a valid port + if(initDesc.port == 0) + { + return false; + } + + this->initDesc = initDesc; + + //Initiate listener + listener = new Listener(); + ((Listener*)listener)->Init(this->initDesc.port, false); + + return true; +} + +bool IServer::PrivateData::Start() +{ + //Start listener + ((Listener*)listener)->Start(); + started = true; + + return true; +} + +bool IServer::PrivateData::Stop() +{ + if(listener) + { + ((Listener*)listener)->Stop(); + } + + started = false; + + return true; +} + +bool IServer::PrivateData::Shutdown() +{ + if(listener) + { + delete listener; + listener = NULL; + } + + started = false; + + return true; +} + +/************************************* + IServer +*************************************/ IServer::IServer() { - + privateData = new PrivateData(); } IServer::~IServer() { - + if(privateData) + { + delete privateData; + } } bool IServer::Init(INIT_DESC& initDesc) { + privateData->Init(initDesc); return true; } bool IServer::Start() { + privateData->Start(); return true; } bool IServer::Stop() { + privateData->Stop(); return true; } bool IServer::Shutdown() { + privateData->Shutdown(); return true; } @@ -42,4 +146,9 @@ void IServer::AddSession(ISession* session) void IServer::RemoveSession(ISession* session) { +} + +bool IServer::IsStarted() const +{ + return privateData->started; } \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/IServer.h b/Code/Network/OysterNetworkServer/IServer.h index cdb1131a..e7382192 100644 --- a/Code/Network/OysterNetworkServer/IServer.h +++ b/Code/Network/OysterNetworkServer/IServer.h @@ -5,30 +5,44 @@ // Created by Pontus Fransson 2013 // ///////////////////////////////////// -class IServer +#include "IClient.h" + +namespace Oyster { - class ISession; - -public: - struct INIT_DESC + namespace Network { + namespace Server + { + class IServer + { + class ISession; + public: + struct INIT_DESC + { + unsigned short port; //Port the server should be accepting clients on. + void (*proc)(IClient*); + }; - }; + IServer(); + virtual ~IServer(); - IServer(); - virtual ~IServer(); + virtual bool Init(INIT_DESC& initDesc); + virtual bool Start(); + virtual bool Stop(); + virtual bool Shutdown(); - virtual bool Init(INIT_DESC& initDesc); - virtual bool Start(); - virtual bool Stop(); - virtual bool Shutdown(); + virtual void AddSession(ISession* session); + virtual void RemoveSession(ISession* session); - virtual void AddSession(ISession* session); - virtual void RemoveSession(ISession* session); + virtual bool IsStarted() const; -private: + private: + struct PrivateData; + PrivateData* privateData; - -}; + }; + } + } +} #endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index f8c262de..ced434ff 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -13,6 +13,7 @@ #include "../../Misc/Utilities-Impl.h" #include "IServer.h" +#include "IClient.h" #include "ISession.h" #pragma comment(lib, "ws2_32.lib") @@ -25,18 +26,15 @@ using namespace Utility; using namespace ::Utility::DynamicMemory; void PrintOutMessage(ProtocolSet* set); +void clientProc(IClient* client); +vector clients; int main() { - IServer server; - IServer::INIT_DESC initDesc; - server.Init(initDesc); - - - //Old program SmartPointer sendBuffer = new OysterByte; - SmartPointer recvBuffer = new OysterByte(); + SmartPointer recvBuffer = new OysterByte; ProtocolSet* set = new ProtocolSet; + IPostBox> *postBox = new PostBox>(); IPostBox> *recvPostBox = new PostBox>(); @@ -48,11 +46,18 @@ int main() { cout << "errorMessage: unable to start winsock" << endl; } - + /* + IServer server; + IServer::INIT_DESC initDesc; + initDesc.port = 9876; + initDesc.proc = clientProc; + server.Init(initDesc); + */ //Create socket Listener listener; listener.Init(9876); listener.SetPostBox(postBox); + listener.Start(); Sleep(1000); //Start listening @@ -72,7 +77,6 @@ int main() WinTimer timer; - vector clients; SmartPointer client = int(); while(1) { @@ -101,21 +105,22 @@ int main() { t.Unpack(set, recvBuffer); - PrintOutMessage(set); + //PrintOutMessage(set); set->Release(); } Sleep(1); } + //server.Stop(); + //server.Shutdown(); listener.Shutdown(); Sleep(1000); system("pause"); - for(int i = 0; i < clients.size(); i++) + for(int i = 0; i < (int)clients.size(); i++) delete clients.at(i); - delete postBox; return 0; } @@ -143,4 +148,10 @@ void PrintOutMessage(ProtocolSet* set) cout << endl; break; } +} + +void clientProc(IClient* client) +{ + cout << "Proc" << endl; + //clients.push_back(client); } \ No newline at end of file From b72fb21b07d5f6543a7fbc898a01f2319298d4b9 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Mon, 9 Dec 2013 10:48:43 +0100 Subject: [PATCH 14/17] Network - Fixed all thread related crashes. The crashes was caused by OysterMutex, so i changed all OysterMutex to std::mutex instead. --- Code/Misc/ThreadSafeQueue.h | 36 +++++++++---------- Code/Misc/Utilities.h | 4 +-- Code/Network/NetworkDependencies/Listener.cpp | 12 ++++--- Code/Network/NetworkDependencies/Listener.h | 1 + .../NetworkDependencies/OysterByte.cpp | 2 +- .../NetworkDependencies/ThreadedClient.cpp | 29 ++++++--------- .../NetworkDependencies/ThreadedClient.h | 6 ++-- .../OysterNetworkClient/ClientMain.cpp | 1 + .../OysterNetworkServer/ServerMain.cpp | 6 ++++ 9 files changed, 52 insertions(+), 45 deletions(-) diff --git a/Code/Misc/ThreadSafeQueue.h b/Code/Misc/ThreadSafeQueue.h index b26d35ff..eedd9fd9 100644 --- a/Code/Misc/ThreadSafeQueue.h +++ b/Code/Misc/ThreadSafeQueue.h @@ -46,7 +46,7 @@ namespace Oyster Node *front; Node *back; int nrOfNodes; - OysterMutex mutex; + std::mutex stdMutex; }; @@ -68,7 +68,7 @@ namespace Oyster template < typename Type > ThreadSafeQueue::~ThreadSafeQueue() { - this->mutex.LockMutex(); + stdMutex.lock(); if(this->front != NULL) { @@ -87,14 +87,14 @@ namespace Oyster this->back = NULL; } - this->mutex.UnlockMutex(); + stdMutex.unlock(); } template < typename Type > void ThreadSafeQueue::Push(Type item) { - mutex.LockMutex(); + stdMutex.lock(); Node *e = new Node(item); if(this->front != NULL) @@ -111,13 +111,13 @@ namespace Oyster this->nrOfNodes++; - mutex.UnlockMutex(); + stdMutex.unlock(); } template < typename Type > Type ThreadSafeQueue::Pop() { - mutex.LockMutex(); + stdMutex.lock(); Type item = this->front->item; Node *destroyer = this->front; @@ -132,16 +132,16 @@ namespace Oyster this->back = NULL; } - mutex.UnlockMutex(); + stdMutex.unlock(); return item; } template < typename Type > Type ThreadSafeQueue::Front() { - mutex.LockMutex(); + stdMutex.lock(); Type temp = this->front->item; - mutex.UnlockMutex(); + stdMutex.unlock(); return temp; @@ -150,9 +150,9 @@ namespace Oyster template < typename Type > Type ThreadSafeQueue::Back() { - mutex.LockMutex(); + stdMutex.lock(); Type temp = this->back->item; - mutex.UnlockMutex(); + stdMutex.unlock(); return temp; @@ -161,9 +161,9 @@ namespace Oyster template < typename Type > int ThreadSafeQueue::Size() { - mutex.LockMutex(); + stdMutex.lock(); int size = this->nrOfNodes; - mutex.UnlockMutex(); + stdMutex.unlock(); return size; @@ -172,16 +172,16 @@ namespace Oyster template < typename Type > bool ThreadSafeQueue::IsEmpty() { - mutex.LockMutex(); + stdMutex.lock(); if(nrOfNodes == 0 || this->front == NULL) { - mutex.UnlockMutex(); + stdMutex.unlock(); return true; } else { - mutex.UnlockMutex(); + stdMutex.unlock(); } return false; @@ -190,7 +190,7 @@ namespace Oyster template < typename Type > void ThreadSafeQueue::Swap(IQueue &queue ) { - mutex.LockMutex(); + stdMutex.lock(); int prevNrOfNodes = this->nrOfNodes; int size = queue.Size(); @@ -203,7 +203,7 @@ namespace Oyster { queue.Push(this->Pop()); } - mutex.UnlockMutex(); + stdMutex.unlock(); } diff --git a/Code/Misc/Utilities.h b/Code/Misc/Utilities.h index ec8b0229..a8e4b406 100644 --- a/Code/Misc/Utilities.h +++ b/Code/Misc/Utilities.h @@ -201,7 +201,6 @@ namespace Utility T *_ptr; /** Destroys the pointer and returns the memory allocated. */ - void Destroy(); public: SmartPointer(); @@ -216,7 +215,8 @@ namespace Utility T* operator-> (); operator T* (); operator bool(); - + + void Destroy(); /** * Returns the connected pointer */ diff --git a/Code/Network/NetworkDependencies/Listener.cpp b/Code/Network/NetworkDependencies/Listener.cpp index 6a9fbeb5..d606df10 100644 --- a/Code/Network/NetworkDependencies/Listener.cpp +++ b/Code/Network/NetworkDependencies/Listener.cpp @@ -60,9 +60,11 @@ void Listener::Shutdown() void Listener::SetPostBox(Oyster::Network::IPostBox>* postBox) { - mutex.LockMutex(); + stdMutex.lock(); + //mutex.LockMutex(); this->postBox = postBox; - mutex.UnlockMutex(); + //mutex.UnlockMutex(); + stdMutex.unlock(); } int Listener::Accept() @@ -72,9 +74,11 @@ int Listener::Accept() if(*clientSocket != -1) { - mutex.LockMutex(); + stdMutex.lock(); + //mutex.LockMutex(); postBox->PostMessage(clientSocket); - mutex.UnlockMutex(); + //mutex.UnlockMutex(); + stdMutex.unlock(); } return clientSocket; diff --git a/Code/Network/NetworkDependencies/Listener.h b/Code/Network/NetworkDependencies/Listener.h index 16b884dd..abf57ba9 100644 --- a/Code/Network/NetworkDependencies/Listener.h +++ b/Code/Network/NetworkDependencies/Listener.h @@ -48,6 +48,7 @@ namespace Oyster ::Oyster::Thread::OysterThread thread; OysterMutex mutex; + std::mutex stdMutex; IPostBox>* postBox; diff --git a/Code/Network/NetworkDependencies/OysterByte.cpp b/Code/Network/NetworkDependencies/OysterByte.cpp index 0ae7bf96..a0883604 100644 --- a/Code/Network/NetworkDependencies/OysterByte.cpp +++ b/Code/Network/NetworkDependencies/OysterByte.cpp @@ -18,7 +18,7 @@ OysterByte::OysterByte(int cap) OysterByte::OysterByte(const OysterByte& obj) { - delete[] this->byteArray; + //delete[] this->byteArray; this->byteArray = new unsigned char[obj.capacity]; for(int i = 0; i < obj.size; i++) diff --git a/Code/Network/NetworkDependencies/ThreadedClient.cpp b/Code/Network/NetworkDependencies/ThreadedClient.cpp index ba6b2c3b..a49caabd 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.cpp +++ b/Code/Network/NetworkDependencies/ThreadedClient.cpp @@ -51,46 +51,37 @@ ThreadedClient::~ThreadedClient() } } -int ThreadedClient::Send(SmartPointer& byte) +void ThreadedClient::Send(SmartPointer& byte) { - SmartPointer temp = new OysterByte(*byte); - - mutex.LockMutex(); - this->sendPostBox->PostMessage(temp); - mutex.UnlockMutex(); - - return 0; + this->sendPostBox->PostMessage(byte); } int ThreadedClient::Send() { int errorCode = 0; - mutex.LockMutex(); if(sendPostBox->IsFull()) { SmartPointer temp = new OysterByte; sendPostBox->FetchMessage(temp); errorCode = this->connection->Send(temp); } - mutex.UnlockMutex(); - return errorCode; } int ThreadedClient::Recv() { - int errorCode = 0; - + int errorCode = -1; + SmartPointer temp = new OysterByte; errorCode = this->connection->Recieve(temp); if(errorCode == 0) { - mutex.LockMutex(); + stdMutex.lock(); recvPostBox->PostMessage(temp); - mutex.UnlockMutex(); + stdMutex.unlock(); } return errorCode; @@ -106,6 +97,8 @@ void ThreadedClient::ThreadExit() std::cout << "Client Thread exit" << std::endl; } +#include + bool ThreadedClient::DoWork() { int errorCode; @@ -120,7 +113,7 @@ bool ThreadedClient::DoWork() { return false; }*/ - + Sleep(1); return true; } @@ -144,7 +137,7 @@ int ThreadedClient::Connect(unsigned short port, const char serverName[]) void ThreadedClient::setRecvPostBox(IPostBox> *postBox) { - this->mutex.LockMutex(); + stdMutex.lock(); this->recvPostBox = postBox; - this->mutex.UnlockMutex(); + stdMutex.unlock(); } \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/ThreadedClient.h b/Code/Network/NetworkDependencies/ThreadedClient.h index 3d12ab6f..ae026a61 100644 --- a/Code/Network/NetworkDependencies/ThreadedClient.h +++ b/Code/Network/NetworkDependencies/ThreadedClient.h @@ -12,6 +12,8 @@ #include "../../Misc/Thread/OysterMutex.h" #include "../../Misc/Utilities.h" +#include + namespace Oyster { namespace Network @@ -25,7 +27,7 @@ namespace Oyster ThreadedClient(IPostBox> *postBox, unsigned int socket); virtual ~ThreadedClient(); - int Send(Utility::DynamicMemory::SmartPointer& byte); + void Send(Utility::DynamicMemory::SmartPointer& byte); int Connect(unsigned short port, const char serverName[]); @@ -44,7 +46,7 @@ namespace Oyster IPostBox> *sendPostBox; IPostBox> *recvPostBox; Oyster::Thread::OysterThread thread; - OysterMutex mutex; + std::mutex stdMutex; }; } diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index 95f966b8..72c011a2 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -95,6 +95,7 @@ void chat(ThreadedClient &client) timer.reset(); client.Send(msgSend); } + Sleep(1); } delete postBox; diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index ced434ff..9564a024 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -76,6 +76,12 @@ int main() t.Pack(test, sendBuffer); WinTimer timer; + + /* DEBUGGING: Connect 25 clients + for(int i = 0; i < 25; i++) + { + clients.push_back(new ThreadedClient(recvPostBox, 1)); + }*/ SmartPointer client = int(); while(1) From 5473c5160fa8c91c9f1bf2059fdce0355ec305d9 Mon Sep 17 00:00:00 2001 From: dean11 Date: Mon, 9 Dec 2013 14:23:30 +0100 Subject: [PATCH 15/17] NETWORK - Modified the protocol creation structure --- Code/DanBias.sln | 196 +++++++----- Code/Network/NetworkAPI/CustomNetProtocol.cpp | 58 ++++ .../CustomNetProtocol.h | 31 +- .../NetworkAPI.vcxproj} | 4 +- .../NetworkProtocol/CustomNetProtocol.cpp | 296 ------------------ 5 files changed, 190 insertions(+), 395 deletions(-) create mode 100644 Code/Network/NetworkAPI/CustomNetProtocol.cpp rename Code/Network/{NetworkProtocol => NetworkAPI}/CustomNetProtocol.h (59%) rename Code/Network/{NetworkProtocol/NetworkProtocol.vcxproj => NetworkAPI/NetworkAPI.vcxproj} (98%) delete mode 100644 Code/Network/NetworkProtocol/CustomNetProtocol.cpp diff --git a/Code/DanBias.sln b/Code/DanBias.sln index 2e047aee..32915f21 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -23,13 +23,26 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OysterNetworkServer", "Netw EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NetworkDependencies", "Network\NetworkDependencies\NetworkDependencies.vcxproj", "{C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameLogic", "GameLogic\GameLogic.vcxproj", "{B1195BB9-B3A5-47F0-906C-8DEA384D1520}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GamePhysics", "GamePhysics\GamePhysics.vcxproj", "{104FA3E9-94D9-4E1D-A941-28A03BC8A095}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tester", "Tester\Tester.vcxproj", "{1B3BEA4C-CF75-438A-9693-60FB8444BBF3}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasGame", "DanBiasGame\DanBiasGame.vcxproj", "{2A1BC987-AF42-4500-802D-89CD32FC1309}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasGame", "Game\DanBiasGame\DanBiasGame.vcxproj", "{2A1BC987-AF42-4500-802D-89CD32FC1309}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Game", "Game", "{20720CA7-795C-45AD-A302-9383A6DD503A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameLogic", "Game\GameLogic\GameLogic.vcxproj", "{B1195BB9-B3A5-47F0-906C-8DEA384D1520}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasServer", "Game\DanBiasServer\DanBiasServer.vcxproj", "{52380DAA-0F4A-4D97-8E57-98DF39319CAF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasLauncher", "Game\DanBiasLauncher\DanBiasLauncher.vcxproj", "{8690FDDF-C5B7-4C42-A337-BD5243F29B85}" + ProjectSection(ProjectDependencies) = postProject + {52380DAA-0F4A-4D97-8E57-98DF39319CAF} = {52380DAA-0F4A-4D97-8E57-98DF39319CAF} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NetworkAPI", "Network\NetworkAPI\NetworkAPI.vcxproj", "{460D625F-2AC9-4559-B809-0BA89CEAEDF4}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameProtocols", "Game\GameProtocols\GameProtocols.vcxproj", "{DA2AA800-ED64-4649-8B3B-E7F1E3968B78}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -41,162 +54,137 @@ Global Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Mixed Platforms.Build.0 = Release|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Win32.ActiveCfg = Debug|Win32 - {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|Win32.Build.0 = Debug|Win32 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|x64.ActiveCfg = Debug|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Debug|x64.Build.0 = Debug|x64 - {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Mixed Platforms.Build.0 = Release|Win32 + {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Mixed Platforms.Build.0 = Release|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Win32.ActiveCfg = Release|Win32 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|Win32.Build.0 = Release|Win32 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|x64.ActiveCfg = Release|x64 {0EC83E64-230E-48EF-B08C-6AC9651B4F82}.Release|x64.Build.0 = Release|x64 - {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Mixed Platforms.Build.0 = Release|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Win32.ActiveCfg = Debug|Win32 - {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|Win32.Build.0 = Debug|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|x64.ActiveCfg = Debug|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Debug|x64.Build.0 = Debug|x64 - {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Mixed Platforms.Build.0 = Release|Win32 + {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Mixed Platforms.Build.0 = Release|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Win32.ActiveCfg = Release|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|Win32.Build.0 = Release|Win32 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|x64.ActiveCfg = Release|x64 {F10CBC03-9809-4CBA-95D8-327C287B18EE}.Release|x64.Build.0 = Release|x64 - {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Mixed Platforms.Build.0 = Release|x64 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Win32.ActiveCfg = Debug|Win32 - {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|Win32.Build.0 = Debug|Win32 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|x64.ActiveCfg = Debug|x64 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Debug|x64.Build.0 = Debug|x64 - {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Mixed Platforms.Build.0 = Release|Win32 + {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Mixed Platforms.Build.0 = Release|x64 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Win32.ActiveCfg = Release|Win32 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|Win32.Build.0 = Release|Win32 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|x64.ActiveCfg = Release|x64 {4285BD3F-3C6C-4670-B7AF-A29AFEF5F6A8}.Release|x64.Build.0 = Release|x64 - {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Mixed Platforms.Build.0 = Release|x64 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Win32.ActiveCfg = Debug|Win32 - {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|Win32.Build.0 = Debug|Win32 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|x64.ActiveCfg = Debug|x64 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Debug|x64.Build.0 = Debug|x64 - {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Mixed Platforms.Build.0 = Release|Win32 + {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Mixed Platforms.Build.0 = Release|x64 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Win32.ActiveCfg = Release|Win32 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|Win32.Build.0 = Release|Win32 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|x64.ActiveCfg = Release|x64 {34D6295A-00DD-4B1A-8258-97DA2818EC26}.Release|x64.Build.0 = Release|x64 - {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Mixed Platforms.Build.0 = Release|x64 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Win32.ActiveCfg = Debug|Win32 - {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|Win32.Build.0 = Debug|Win32 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|x64.ActiveCfg = Debug|x64 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Debug|x64.Build.0 = Debug|x64 - {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Mixed Platforms.Build.0 = Release|Win32 + {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Mixed Platforms.Build.0 = Release|x64 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Win32.ActiveCfg = Release|Win32 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|Win32.Build.0 = Release|Win32 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|x64.ActiveCfg = Release|x64 {35AEA3C0-E0A7-4E1E-88CD-514AA5A442B1}.Release|x64.Build.0 = Release|x64 - {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Mixed Platforms.Build.0 = Release|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Win32.ActiveCfg = Debug|Win32 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|Win32.Build.0 = Debug|Win32 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|x64.ActiveCfg = Debug|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Debug|x64.Build.0 = Debug|x64 - {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Mixed Platforms.Build.0 = Release|Win32 + {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Mixed Platforms.Build.0 = Release|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Win32.ActiveCfg = Release|Win32 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|Win32.Build.0 = Release|Win32 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|x64.ActiveCfg = Release|x64 {7E3990D2-3D94-465C-B58D-64A74B3ECF9B}.Release|x64.Build.0 = Release|x64 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Mixed Platforms.Build.0 = Release|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Win32.ActiveCfg = Debug|Win32 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|Win32.Build.0 = Debug|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|x64.ActiveCfg = Debug|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Debug|x64.Build.0 = Debug|x64 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Mixed Platforms.Build.0 = Release|Win32 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Mixed Platforms.Build.0 = Release|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Win32.ActiveCfg = Release|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|Win32.Build.0 = Release|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|x64.ActiveCfg = Release|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.Release|x64.Build.0 = Release|x64 - {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Mixed Platforms.Build.0 = Release|x64 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Win32.ActiveCfg = Debug|Win32 - {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|Win32.Build.0 = Debug|Win32 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|x64.ActiveCfg = Debug|x64 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Debug|x64.Build.0 = Debug|x64 - {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Mixed Platforms.Build.0 = Release|Win32 + {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Mixed Platforms.Build.0 = Release|x64 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Win32.ActiveCfg = Release|Win32 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|Win32.Build.0 = Release|Win32 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|x64.ActiveCfg = Release|x64 {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8}.Release|x64.Build.0 = Release|x64 - {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Mixed Platforms.Build.0 = Release|x64 {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Win32.ActiveCfg = Debug|Win32 - {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|Win32.Build.0 = Debug|Win32 {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|x64.ActiveCfg = Debug|x64 {6A066806-F43F-4B31-A4E3-57179674F460}.Debug|x64.Build.0 = Debug|x64 - {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Mixed Platforms.Build.0 = Release|Win32 + {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Mixed Platforms.Build.0 = Release|x64 {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Win32.ActiveCfg = Release|Win32 {6A066806-F43F-4B31-A4E3-57179674F460}.Release|Win32.Build.0 = Release|Win32 {6A066806-F43F-4B31-A4E3-57179674F460}.Release|x64.ActiveCfg = Release|x64 {6A066806-F43F-4B31-A4E3-57179674F460}.Release|x64.Build.0 = Release|x64 - {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.ActiveCfg = Release|x64 + {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.Build.0 = Release|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Win32.ActiveCfg = Debug|Win32 - {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Win32.Build.0 = Debug|Win32 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|x64.ActiveCfg = Debug|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|x64.Build.0 = Debug|x64 - {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Mixed Platforms.Build.0 = Release|Win32 + {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Mixed Platforms.ActiveCfg = Release|x64 + {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Mixed Platforms.Build.0 = Release|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Win32.ActiveCfg = Release|Win32 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Win32.Build.0 = Release|Win32 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|x64.ActiveCfg = Release|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|x64.Build.0 = Release|x64 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Win32.ActiveCfg = Debug|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Win32.Build.0 = Debug|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|x64.ActiveCfg = Debug|x64 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|x64.Build.0 = Debug|x64 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Mixed Platforms.Build.0 = Release|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Win32.ActiveCfg = Release|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Win32.Build.0 = Release|Win32 - {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|x64.ActiveCfg = Release|Win32 - {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Mixed Platforms.ActiveCfg = Release|Win32 + {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Mixed Platforms.Build.0 = Release|Win32 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Win32.ActiveCfg = Debug|Win32 - {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|Win32.Build.0 = Debug|Win32 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|x64.ActiveCfg = Debug|x64 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Debug|x64.Build.0 = Debug|x64 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Mixed Platforms.ActiveCfg = Release|Win32 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Mixed Platforms.Build.0 = Release|Win32 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Win32.ActiveCfg = Release|Win32 {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|Win32.Build.0 = Release|Win32 - {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|x64.ActiveCfg = Release|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|x64.ActiveCfg = Release|x64 + {104FA3E9-94D9-4E1D-A941-28A03BC8A095}.Release|x64.Build.0 = Release|x64 + {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Mixed Platforms.ActiveCfg = Release|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Win32.ActiveCfg = Debug|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|Win32.Build.0 = Debug|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|x64.ActiveCfg = Debug|x64 + {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Debug|x64.ActiveCfg = Debug|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Mixed Platforms.Build.0 = Release|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Win32.ActiveCfg = Release|Win32 - {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|Win32.Build.0 = Release|Win32 {1B3BEA4C-CF75-438A-9693-60FB8444BBF3}.Release|x64.ActiveCfg = Release|Win32 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Win32.ActiveCfg = Debug|Win32 - {2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|Win32.Build.0 = Debug|Win32 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|x64.ActiveCfg = Debug|x64 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Debug|x64.Build.0 = Debug|x64 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|Mixed Platforms.ActiveCfg = Release|Win32 @@ -205,6 +193,60 @@ Global {2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|Win32.Build.0 = Release|Win32 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|x64.ActiveCfg = Release|x64 {2A1BC987-AF42-4500-802D-89CD32FC1309}.Release|x64.Build.0 = Release|x64 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|Win32.ActiveCfg = Debug|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|x64.ActiveCfg = Debug|x64 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Debug|x64.Build.0 = Debug|x64 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Mixed Platforms.Build.0 = Release|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Win32.ActiveCfg = Release|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|Win32.Build.0 = Release|Win32 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|x64.ActiveCfg = Release|x64 + {B1195BB9-B3A5-47F0-906C-8DEA384D1520}.Release|x64.Build.0 = Release|x64 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|Win32.ActiveCfg = Debug|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|x64.ActiveCfg = Debug|x64 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Debug|x64.Build.0 = Debug|x64 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Mixed Platforms.Build.0 = Release|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Win32.ActiveCfg = Release|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|Win32.Build.0 = Release|Win32 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|x64.ActiveCfg = Release|x64 + {52380DAA-0F4A-4D97-8E57-98DF39319CAF}.Release|x64.Build.0 = Release|x64 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|Win32.ActiveCfg = Debug|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|x64.ActiveCfg = Debug|x64 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Debug|x64.Build.0 = Debug|x64 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|Mixed Platforms.Build.0 = Release|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|Win32.ActiveCfg = Release|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|Win32.Build.0 = Release|Win32 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|x64.ActiveCfg = Release|x64 + {8690FDDF-C5B7-4C42-A337-BD5243F29B85}.Release|x64.Build.0 = Release|x64 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Win32.ActiveCfg = Debug|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|x64.ActiveCfg = Debug|x64 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|x64.Build.0 = Debug|x64 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|Mixed Platforms.Build.0 = Release|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|Win32.ActiveCfg = Release|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|Win32.Build.0 = Release|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|x64.ActiveCfg = Release|x64 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|x64.Build.0 = Release|x64 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|Win32.ActiveCfg = Debug|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|x64.ActiveCfg = Debug|x64 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Debug|x64.Build.0 = Debug|x64 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|Mixed Platforms.Build.0 = Release|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|Win32.ActiveCfg = Release|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|Win32.Build.0 = Release|Win32 + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -213,5 +255,11 @@ Global {838B25C2-D19E-49FE-8CB0-9A977CA3C7E8} = {C27B926E-B3EF-4990-8822-47580E43A0BE} {6A066806-F43F-4B31-A4E3-57179674F460} = {C27B926E-B3EF-4990-8822-47580E43A0BE} {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50} = {C27B926E-B3EF-4990-8822-47580E43A0BE} + {460D625F-2AC9-4559-B809-0BA89CEAEDF4} = {C27B926E-B3EF-4990-8822-47580E43A0BE} + {2A1BC987-AF42-4500-802D-89CD32FC1309} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {B1195BB9-B3A5-47F0-906C-8DEA384D1520} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {52380DAA-0F4A-4D97-8E57-98DF39319CAF} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {DA2AA800-ED64-4649-8B3B-E7F1E3968B78} = {20720CA7-795C-45AD-A302-9383A6DD503A} EndGlobalSection EndGlobal diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.cpp b/Code/Network/NetworkAPI/CustomNetProtocol.cpp new file mode 100644 index 00000000..b636a475 --- /dev/null +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -0,0 +1,58 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// +#include "CustomNetProtocol.h" +#include + +using namespace Network; + + +struct CustomNetProtocol::PrivateData +{ + std::map attributes; + + PrivateData() + { } + ~PrivateData() + { + for (auto i = attributes.begin(); i != attributes.end(); i++) + { + RemoveAttribute(i->first); + } + } + void RemoveAttribute(int ID) + { + auto i = attributes.find(ID); + if(i == attributes.end()) return; + + switch (i->second.type) + { + case NetAttributeType_CharArray: + delete [] i->second.value.netCharPtr; + break; + } + } + + //Do network stuff +}; + + +CustomNetProtocol::CustomNetProtocol() +{ + this->privateData = new PrivateData(); +} +CustomNetProtocol::~CustomNetProtocol() +{ + delete this->privateData; +} +NetAttributeContainer& CustomNetProtocol::operator[](int ID) +{ + if(this->privateData->attributes.find(ID) == this->privateData->attributes.end()) + { + this->privateData->attributes[ID]; + this->privateData->attributes[ID].type = NetAttributeType_UNKNOWN; + memset(&this->privateData->attributes[ID].value, 0, sizeof(NetAttributeValue)); + } + + return this->privateData->attributes[ID]; +} diff --git a/Code/Network/NetworkProtocol/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h similarity index 59% rename from Code/Network/NetworkProtocol/CustomNetProtocol.h rename to Code/Network/NetworkAPI/CustomNetProtocol.h index 2845250f..9e464f9f 100644 --- a/Code/Network/NetworkProtocol/CustomNetProtocol.h +++ b/Code/Network/NetworkAPI/CustomNetProtocol.h @@ -46,7 +46,7 @@ namespace Network float netFloat; double netDouble; char* netCharPtr; - + NetAttributeValue(){ memset(this, 0, sizeof(NetAttributeValue)); } NetAttributeValue(bool v) : netBool (v) {} NetAttributeValue(char v) : netChar (v) {} @@ -67,34 +67,19 @@ namespace Network NetAttributeValue value; NetAttributeContainer() { type = NetAttributeType_UNKNOWN; } }; + class CustomNetProtocol; + struct CustomProtocolObject + { + virtual CustomNetProtocol* GetProtocol() = 0; + }; + class NET_PROTOCOL_EXPORT CustomNetProtocol { public: CustomNetProtocol(); ~CustomNetProtocol(); - NetAttributeContainer* operator[](int ID); - - NetAttributeContainer* BuildValue(NetAttributeContainer value, short attributeId); - NetAttributeContainer* BuildValue(NetAttributeValue value, NetAttributeType type, short attributeId); - NetAttributeContainer* BuildValue(const bool & attribute, short attributeId); - NetAttributeContainer* BuildValue(const char & attribute, short attributeId); - NetAttributeContainer* BuildValue(const unsigned char & attribute, short attributeId); - NetAttributeContainer* BuildValue(const short & attribute, short attributeId); - NetAttributeContainer* BuildValue(const unsigned short & attribute, short attributeId); - NetAttributeContainer* BuildValue(const int & attribute, short attributeId); - NetAttributeContainer* BuildValue(const unsigned int & attribute, short attributeId); - NetAttributeContainer* BuildValue(const __int64 & attribute, short attributeId); - NetAttributeContainer* BuildValue(const unsigned __int64 & attribute, short attributeId); - NetAttributeContainer* BuildValue(const float & attribute, short attributeId); - NetAttributeContainer* BuildValue(const double & attribute, short attributeId); - NetAttributeContainer* BuildValue(const std::string & attribute, short attributeId); - NetAttributeContainer* BuildValue(const char * attribute, short attributeId); - - //void SetArrayValue(NetAttributeContainer attribute[], unsigned int attributeCount, int attributeId); - - NetAttributeContainer& GetSingleValue(int attributeID); - //NetAttributeContainer* GetArrayValue(int attributeID); + NetAttributeContainer& operator[](int ID); private: struct PrivateData; diff --git a/Code/Network/NetworkProtocol/NetworkProtocol.vcxproj b/Code/Network/NetworkAPI/NetworkAPI.vcxproj similarity index 98% rename from Code/Network/NetworkProtocol/NetworkProtocol.vcxproj rename to Code/Network/NetworkAPI/NetworkAPI.vcxproj index 36dddd75..adb00d01 100644 --- a/Code/Network/NetworkProtocol/NetworkProtocol.vcxproj +++ b/Code/Network/NetworkAPI/NetworkAPI.vcxproj @@ -21,8 +21,8 @@ {460D625F-2AC9-4559-B809-0BA89CEAEDF4} Win32Proj - NetworkProtocol - NetworkProtocol + NetworkAPI + NetworkAPI diff --git a/Code/Network/NetworkProtocol/CustomNetProtocol.cpp b/Code/Network/NetworkProtocol/CustomNetProtocol.cpp deleted file mode 100644 index ef9d3fc2..00000000 --- a/Code/Network/NetworkProtocol/CustomNetProtocol.cpp +++ /dev/null @@ -1,296 +0,0 @@ -///////////////////////////////////////////////////////////////////// -// Created by [Dennis Andersen] [2013] -///////////////////////////////////////////////////////////////////// -#include "CustomNetProtocol.h" -#include - -using namespace Network; - -enum NetContainerType -{ - NetContainer_Array, - NetContainer_Single, - NetContainer_UNKNOWN, -}; -struct NetAttributeArray -{ - NetAttributeContainer *value; - int count; - NetAttributeArray() - :value(0) - , count(0) - {} -}; -union NetAttributeData -{ - struct { NetAttributeContainer singleVal; }; - struct { NetAttributeArray arrayVal; }; -}; -struct NetDataValue -{ - NetContainerType containerType; - NetAttributeData attributeData; - NetDataValue() - { - //memset(&attributeData, 0, sizeof(NetAttributeData)); - containerType = NetContainer_UNKNOWN; - attributeData.singleVal.type = NetAttributeType_UNKNOWN; - } -}; - - - -struct CustomNetProtocol::PrivateData -{ - std::map attributes; - //DataValue *val; - //unsigned int size; - - PrivateData() - { - //val = new DataValue[_size]; - //size = _size; - } - ~PrivateData() - { - for (auto i = attributes.begin(); i != attributes.end(); i++) - { - RemoveAttribute(i->first); - } - } - void RemoveAttribute(int ID) - { - auto i = attributes.find(ID); - if(i == attributes.end()) return; - - if(i->second.containerType == NetContainer_Single) - { - switch (i->second.attributeData.singleVal.type) - { - case NetAttributeType_CharArray: - delete [] i->second.attributeData.singleVal.value.netCharPtr; - break; - } - } - else if(i->second.containerType == NetContainer_Array) - { - } - - } - - //Do network stuff -}; - - -CustomNetProtocol::CustomNetProtocol() -{ - this->privateData = new PrivateData(); -} -CustomNetProtocol::~CustomNetProtocol() -{ - delete this->privateData; -} -NetAttributeContainer* CustomNetProtocol::operator[](int ID) -{ - NetAttributeContainer *retVal = 0; - - if(this->privateData->attributes.find(ID) == this->privateData->attributes.end()) - return retVal; - - if(this->privateData->attributes[ID].containerType == NetContainer_Single) - retVal = &this->privateData->attributes[ID].attributeData.singleVal; - - if(this->privateData->attributes[ID].containerType == NetContainer_Array) - retVal = this->privateData->attributes[ID].attributeData.arrayVal.value; - - return retVal; -} - - -NetAttributeContainer* CustomNetProtocol::BuildValue(NetAttributeContainer val, short ID) -{ - if(val.type == NetAttributeType_UNKNOWN) return 0; - - this->privateData->RemoveAttribute(ID); - - this->privateData->attributes[ID].attributeData.singleVal = val; - - return &this->privateData->attributes[ID].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(NetAttributeValue value, NetAttributeType type, short ID) -{ - if(type == NetAttributeType_UNKNOWN) return 0; - - this->privateData->RemoveAttribute(ID); - - this->privateData->attributes[ID].attributeData.singleVal.value = value; - this->privateData->attributes[ID].attributeData.singleVal.type = type; - - return &this->privateData->attributes[ID].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const bool & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netBool = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Bool; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const char & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netChar = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Char; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const unsigned char & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netUChar = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_UnsignedChar; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const short & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netShort = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Short; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const unsigned short & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netUShort = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_UnsignedShort; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const int & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netInt = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Int; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const unsigned int & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netUInt = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_UnsignedInt; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const __int64 & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netInt64 = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Int64; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const unsigned __int64 & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netUInt64 = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_UnsignedInt64; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const float & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netFloat = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Float; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const double & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netDouble = attribute; - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_Double; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const std::string & attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netCharPtr = _strdup(attribute.c_str()); - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_CharArray; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} -NetAttributeContainer* CustomNetProtocol::BuildValue(const char* attribute, short attributeId) -{ - this->privateData->RemoveAttribute(attributeId); - - this->privateData->attributes[attributeId].attributeData.singleVal.value.netCharPtr = _strdup(attribute); - this->privateData->attributes[attributeId].attributeData.singleVal.type = NetAttributeType_CharArray; - this->privateData->attributes[attributeId].containerType = NetContainer_Single; - - return &this->privateData->attributes[attributeId].attributeData.singleVal; -} - - -//void CustomNetProtocol::SetArrayValue(NetAttributeContainer attribute[], unsigned int attributeCount, int ID) -//{ -// if(this->privateData->attributes.find(ID) == this->privateData->attributes.end()) -// { -// this->privateData->attributes[ID] = NetDataValue(); -// } -// -// if(this->privateData->attributes[ID].containerType == NetContainer_UNKNOWN) -// this->privateData->attributes[ID].containerType = NetContainer_Array; -// -// this->privateData->attributes[ID].attributeData.arrayVal.value = attribute; -//} - -NetAttributeContainer& CustomNetProtocol::GetSingleValue(int attributeID) -{ - return this->privateData->attributes[attributeID].attributeData.singleVal; -} -//NetAttributeContainer* CustomNetProtocol::GetArrayValue(int attributeID) -//{ -// return this->privateData->attributes[attributeID].attributeData.arrayVal.value; -//} - - - - - - - - - - - - - From 2cb8bbd8a955fe3f08549295b7b062eb5db5f379 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Mon, 9 Dec 2013 22:22:05 +0100 Subject: [PATCH 16/17] Network - IServer running on separate thread. IServer accepting clients. --- Code/Misc/Utilities.h | 2 +- Code/Network/NetworkDependencies/Listener.cpp | 10 +-- Code/Network/NetworkDependencies/Listener.h | 6 +- .../NetworkDependencies.vcxproj | 1 - .../NetworkDependencies.vcxproj.filters | 1 - Code/Network/NetworkDependencies/main.cpp | 0 Code/Network/OysterNetworkServer/IServer.cpp | 73 ++++++++++++---- Code/Network/OysterNetworkServer/IServer.h | 4 - Code/Network/OysterNetworkServer/ISession.h | 34 -------- .../OysterNetworkServer.vcxproj | 4 +- .../OysterNetworkServer.vcxproj.filters | 10 ++- .../OysterNetworkServer/RecieverObject.h | 19 ++++ .../OysterNetworkServer/ServerMain.cpp | 87 ++++--------------- .../Network/OysterNetworkServer/TestClass.cpp | 62 +++++++++++++ Code/Network/OysterNetworkServer/TestClass.h | 34 ++++++++ 15 files changed, 211 insertions(+), 136 deletions(-) delete mode 100644 Code/Network/NetworkDependencies/main.cpp delete mode 100644 Code/Network/OysterNetworkServer/ISession.h create mode 100644 Code/Network/OysterNetworkServer/RecieverObject.h create mode 100644 Code/Network/OysterNetworkServer/TestClass.cpp create mode 100644 Code/Network/OysterNetworkServer/TestClass.h diff --git a/Code/Misc/Utilities.h b/Code/Misc/Utilities.h index a8e4b406..6112bea1 100644 --- a/Code/Misc/Utilities.h +++ b/Code/Misc/Utilities.h @@ -201,6 +201,7 @@ namespace Utility T *_ptr; /** Destroys the pointer and returns the memory allocated. */ + void Destroy(); public: SmartPointer(); @@ -216,7 +217,6 @@ namespace Utility operator T* (); operator bool(); - void Destroy(); /** * Returns the connected pointer */ diff --git a/Code/Network/NetworkDependencies/Listener.cpp b/Code/Network/NetworkDependencies/Listener.cpp index d606df10..1aec11da 100644 --- a/Code/Network/NetworkDependencies/Listener.cpp +++ b/Code/Network/NetworkDependencies/Listener.cpp @@ -8,7 +8,7 @@ Listener::Listener() connection = NULL; } -Listener::Listener(Oyster::Network::IPostBox>* postBox) +Listener::Listener(Oyster::Network::IPostBox* postBox) { connection = NULL; this->postBox = postBox; @@ -58,7 +58,7 @@ void Listener::Shutdown() thread.Stop(); } -void Listener::SetPostBox(Oyster::Network::IPostBox>* postBox) +void Listener::SetPostBox(Oyster::Network::IPostBox* postBox) { stdMutex.lock(); //mutex.LockMutex(); @@ -69,10 +69,10 @@ void Listener::SetPostBox(Oyster::Network::IPostBox>* postBox) int Listener::Accept() { - SmartPointer clientSocket = SmartPointer(new int()); - *clientSocket = connection->Listen(); + int clientSocket = -1; + clientSocket = connection->Listen(); - if(*clientSocket != -1) + if(clientSocket != -1) { stdMutex.lock(); //mutex.LockMutex(); diff --git a/Code/Network/NetworkDependencies/Listener.h b/Code/Network/NetworkDependencies/Listener.h index abf57ba9..80b7543f 100644 --- a/Code/Network/NetworkDependencies/Listener.h +++ b/Code/Network/NetworkDependencies/Listener.h @@ -22,7 +22,7 @@ namespace Oyster { public: Listener(); - Listener(Oyster::Network::IPostBox>* postBox); + Listener(Oyster::Network::IPostBox* postBox); ~Listener(); bool Init(unsigned int port); @@ -32,7 +32,7 @@ namespace Oyster void Shutdown(); - void SetPostBox(IPostBox>* postBox); + void SetPostBox(IPostBox* postBox); private: //Thread functions @@ -50,7 +50,7 @@ namespace Oyster OysterMutex mutex; std::mutex stdMutex; - IPostBox>* postBox; + IPostBox* postBox; }; } diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj index ca48c730..d33e34d3 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj @@ -153,7 +153,6 @@ - diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index 9d10d4dc..3189aba4 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -3,7 +3,6 @@ - diff --git a/Code/Network/NetworkDependencies/main.cpp b/Code/Network/NetworkDependencies/main.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/Code/Network/OysterNetworkServer/IServer.cpp b/Code/Network/OysterNetworkServer/IServer.cpp index 82d5a155..84da54ba 100644 --- a/Code/Network/OysterNetworkServer/IServer.cpp +++ b/Code/Network/OysterNetworkServer/IServer.cpp @@ -3,16 +3,18 @@ #include "IClient.h" #include "../NetworkDependencies/PostBox.h" #include "../../Misc/Utilities.h" +#include "../../Misc/Thread/OysterThread.h" using namespace Oyster::Network; using namespace ::Server; using namespace Utility::DynamicMemory; +using namespace Oyster::Thread; /************************************* PrivateData *************************************/ -struct IServer::PrivateData +struct IServer::PrivateData : public IThreadObject { PrivateData(); ~PrivateData(); @@ -21,20 +23,29 @@ struct IServer::PrivateData bool Start(); bool Stop(); bool Shutdown(); - + + void CheckForNewClient(); + + virtual bool DoWork(); + // IListener* listener; INIT_DESC initDesc; bool started; - IPostBox> *postBox; + //Postbox for new clients + IPostBox *postBox; + + //Server thread + OysterThread thread; + }; IServer::PrivateData::PrivateData() { listener = 0; started = false; - postBox = new PostBox>(); + postBox = new PostBox; } IServer::PrivateData::~PrivateData() @@ -53,9 +64,11 @@ bool IServer::PrivateData::Init(INIT_DESC& initDesc) this->initDesc = initDesc; //Initiate listener - listener = new Listener(); + listener = new Listener(postBox); ((Listener*)listener)->Init(this->initDesc.port, false); + thread.Create(this, false); + return true; } @@ -65,6 +78,8 @@ bool IServer::PrivateData::Start() ((Listener*)listener)->Start(); started = true; + thread.Start(); + return true; } @@ -77,22 +92,60 @@ bool IServer::PrivateData::Stop() started = false; + thread.Stop(); + return true; } bool IServer::PrivateData::Shutdown() { + //Stop server main thread + thread.Stop(); + if(listener) { delete listener; listener = NULL; } + if(postBox) + { + delete postBox; + postBox = NULL; + } + started = false; return true; } +//Checks for new clients and sends them to the proc function. +void IServer::PrivateData::CheckForNewClient() +{ + if(postBox->IsFull()) + { + int clientSocketNum; + postBox->FetchMessage(clientSocketNum); + + //Safety check that is probably not needed. + if(clientSocketNum == -1) + { + return; + } + + //Create the new client + IClient* client = new IClient(); + initDesc.proc(client); + } +} + +bool IServer::PrivateData::DoWork() +{ + CheckForNewClient(); + + return true; +} + /************************************* IServer *************************************/ @@ -138,16 +191,6 @@ bool IServer::Shutdown() return true; } -void IServer::AddSession(ISession* session) -{ - -} - -void IServer::RemoveSession(ISession* session) -{ - -} - bool IServer::IsStarted() const { return privateData->started; diff --git a/Code/Network/OysterNetworkServer/IServer.h b/Code/Network/OysterNetworkServer/IServer.h index e7382192..0f34fdc3 100644 --- a/Code/Network/OysterNetworkServer/IServer.h +++ b/Code/Network/OysterNetworkServer/IServer.h @@ -15,7 +15,6 @@ namespace Oyster { class IServer { - class ISession; public: struct INIT_DESC { @@ -31,9 +30,6 @@ namespace Oyster virtual bool Stop(); virtual bool Shutdown(); - virtual void AddSession(ISession* session); - virtual void RemoveSession(ISession* session); - virtual bool IsStarted() const; private: diff --git a/Code/Network/OysterNetworkServer/ISession.h b/Code/Network/OysterNetworkServer/ISession.h deleted file mode 100644 index 84ca05e0..00000000 --- a/Code/Network/OysterNetworkServer/ISession.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef OYSTER_NETWORK_SERVER_I_SESSION_H -#define OYSTER_NETWORK_SERVER_I_SESSION_H - -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -class ISession -{ - class IClient; -public: - struct INIT_DESC - { - - }; - - ISession(); - virtual ~ISession(); - - virtual bool Init(); - virtual bool Start(); - virtual bool Stop(); - virtual bool Shutdown(); - - virtual void SendToAll(); - - virtual void AddClient(IClient* client); - virtual void RemoveClient(IClient* client); - -private: -}; - - -#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj index 196da525..82cec50e 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj @@ -156,11 +156,13 @@ + - + + diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters index fc74d185..23947d8a 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters @@ -21,15 +21,21 @@ Source Files + + Source Files + Header Files - + Header Files - + + Header Files + + Header Files diff --git a/Code/Network/OysterNetworkServer/RecieverObject.h b/Code/Network/OysterNetworkServer/RecieverObject.h new file mode 100644 index 00000000..681c7204 --- /dev/null +++ b/Code/Network/OysterNetworkServer/RecieverObject.h @@ -0,0 +1,19 @@ +#ifndef OYSTER_NETWORK_SERVER_RECIEVER_OBJECT_H +#define OYSTER_NETWORK_SERVER_RECIEVER_OBJECT_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#include "../NetworkDependencies/Protocols.h" +#include "../NetworkDependencies/OysterByte.h" +#include "../../Misc/Utilities.h" + +class RecieverObject +{ +public: + virtual void ProcFunc(Utility::DynamicMemory::SmartPointer msg) = 0; + +}; + +#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 9564a024..ce8e2742 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -12,9 +12,9 @@ #include "../../Misc/Utilities.h" #include "../../Misc/Utilities-Impl.h" +#include "TestClass.h" #include "IServer.h" #include "IClient.h" -#include "ISession.h" #pragma comment(lib, "ws2_32.lib") @@ -25,18 +25,15 @@ using namespace ::Protocols; using namespace Utility; using namespace ::Utility::DynamicMemory; -void PrintOutMessage(ProtocolSet* set); void clientProc(IClient* client); -vector clients; int main() { + Test tests; + SmartPointer sendBuffer = new OysterByte; SmartPointer recvBuffer = new OysterByte; ProtocolSet* set = new ProtocolSet; - - IPostBox> *postBox = new PostBox>(); - IPostBox> *recvPostBox = new PostBox>(); cout << "Server" << endl; Translator t; @@ -46,22 +43,17 @@ int main() { cout << "errorMessage: unable to start winsock" << endl; } - /* + IServer server; IServer::INIT_DESC initDesc; initDesc.port = 9876; initDesc.proc = clientProc; server.Init(initDesc); - */ - //Create socket - Listener listener; - listener.Init(9876); - listener.SetPostBox(postBox); - listener.Start(); + server.Start(); + Sleep(1000); - //Start listening - //Accept a client + //Create a test protocol ProtocolPlayerPos test; test.clientID = 0; test.ID = 5; @@ -74,28 +66,14 @@ int main() } t.Pack(test, sendBuffer); - - WinTimer timer; - - /* DEBUGGING: Connect 25 clients - for(int i = 0; i < 25; i++) - { - clients.push_back(new ThreadedClient(recvPostBox, 1)); - }*/ - SmartPointer client = int(); + WinTimer timer; + while(1) { //Fetch new clients from the postbox - if(postBox->FetchMessage(client)) - { - cout << "Client connected: " << *client << endl; - clients.push_back(new ThreadedClient(recvPostBox, *client)); - - clients.at(clients.size()-1)->Send(sendBuffer); - } - - //Send a message every 1 secounds to all clients. + /* + //Send a message every 1 seconds to all clients. if(timer.getElapsedSeconds() > 1) { cout << "Sending to " << clients.size() << " clients." << endl; @@ -104,60 +82,31 @@ int main() { clients.at(i)->Send(sendBuffer); } - } + }*/ - //Fetch messages + /*//Fetch messages if(recvPostBox->FetchMessage(recvBuffer)) { t.Unpack(set, recvBuffer); //PrintOutMessage(set); set->Release(); - } + }*/ Sleep(1); } - //server.Stop(); - //server.Shutdown(); - listener.Shutdown(); + server.Stop(); + server.Shutdown(); + //listener.Shutdown(); Sleep(1000); system("pause"); - for(int i = 0; i < (int)clients.size(); i++) - delete clients.at(i); - return 0; } -void PrintOutMessage(ProtocolSet* set) -{ - switch(set->type) - { - case PackageType_header: - break; - case PackageType_test: - cout <<"Client 2: " << set->Protocol.pTest->textMessage <Protocol.pTest->numOfFloats; i++) - { - cout << set->Protocol.pTest->f[i] << ' ' ; - } - cout << endl; - break; - - case PackageType_player_pos: - //cout << "ID " << set->Protocol.pPlayerPos->ID << endl; - for(int i = 0; i < (int)set->Protocol.pPlayerPos->nrOfFloats; i++) - { - cout << set->Protocol.pPlayerPos->matrix[i] << ' '; - } - cout << endl; - break; - } -} - void clientProc(IClient* client) { cout << "Proc" << endl; - //clients.push_back(client); + clients.push_back(client); } \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/TestClass.cpp b/Code/Network/OysterNetworkServer/TestClass.cpp new file mode 100644 index 00000000..ec50bf9e --- /dev/null +++ b/Code/Network/OysterNetworkServer/TestClass.cpp @@ -0,0 +1,62 @@ +#include "TestClass.h" +#include "../../Misc/WinTimer.h" +#include + +using namespace Oyster::Network; +using namespace ::Protocols; +using namespace Utility; +using namespace ::DynamicMemory; +using namespace std; + +Test::Test() +{ + recvPostBox = new PostBox>; +} + +Test::~Test() +{ + for(int i = 0; i < (int)clients.size(); i++) + delete clients.at(i); +} + +void Test::ProcFunc(Utility::DynamicMemory::SmartPointer msg) +{ + + return; +} + +void Test::mainLoop() +{ + WinTimer timer; + + while(1) + { + + } +} + +void Test::PrintOutMessage(ProtocolSet* set) +{ + switch(set->type) + { + case PackageType_header: + break; + case PackageType_test: + cout <<"Client 2: " << set->Protocol.pTest->textMessage <Protocol.pTest->numOfFloats; i++) + { + cout << set->Protocol.pTest->f[i] << ' ' ; + } + cout << endl; + break; + + case PackageType_player_pos: + //cout << "ID " << set->Protocol.pPlayerPos->ID << endl; + for(int i = 0; i < (int)set->Protocol.pPlayerPos->nrOfFloats; i++) + { + cout << set->Protocol.pPlayerPos->matrix[i] << ' '; + } + cout << endl; + break; + } +} \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/TestClass.h b/Code/Network/OysterNetworkServer/TestClass.h new file mode 100644 index 00000000..e3edf31f --- /dev/null +++ b/Code/Network/OysterNetworkServer/TestClass.h @@ -0,0 +1,34 @@ +#ifndef TEST_CLASS_H +#define TEST_CLASS_H + +#include "RecieverObject.h" +#include "../../Misc/Utilities.h" +#include "../NetworkDependencies/OysterByte.h" +#include "../NetworkDependencies/PostBox.h" +#include "IClient.h" +#include "../NetworkDependencies/Translator.h" +#include + +class Test : public RecieverObject +{ +public: + Test(); + ~Test(); + + void mainLoop(); + + virtual void ProcFunc(Utility::DynamicMemory::SmartPointer msg); + void PrintOutMessage(Oyster::Network::Protocols::ProtocolSet* set); + +private: + std::vector clients; + Oyster::Network::IPostBox> *recvPostBox; + + Oyster::Network::Translator t; + + Oyster::Network::Protocols::ProtocolPlayerPos test; + + +}; + +#endif \ No newline at end of file From e06ee31754c744210636a24f72b4c3730a0bbff9 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 10 Dec 2013 08:32:08 +0100 Subject: [PATCH 17/17] Network - First basic API. --- Code/Network/NetworkAPI/NetworkAPI.vcxproj | 9 +++ Code/Network/NetworkAPI/NetworkClient.cpp | 41 ++++++++++++ Code/Network/NetworkAPI/NetworkClient.h | 42 ++++++++++++ .../NetworkServer.cpp} | 49 ++++++++------ Code/Network/NetworkAPI/NetworkServer.h | 56 ++++++++++++++++ .../NetworkDependencies/Connection.cpp | 6 +- .../Messages/MessageHeader.cpp | 6 +- .../NetworkDependencies/OysterByte.cpp | 4 +- Code/Network/NetworkDependencies/Packing.cpp | 4 +- .../NetworkDependencies/WinsockFunctions.cpp | 2 +- Code/Network/OysterNetworkServer/IClient.h | 23 ------- Code/Network/OysterNetworkServer/IServer.h | 44 ------------ .../OysterNetworkServer.vcxproj | 6 +- .../OysterNetworkServer.vcxproj.filters | 9 --- .../OysterNetworkServer/ServerMain.cpp | 67 ++----------------- .../Network/OysterNetworkServer/TestClass.cpp | 24 +++++++ Code/Network/OysterNetworkServer/TestClass.h | 9 ++- 17 files changed, 224 insertions(+), 177 deletions(-) create mode 100644 Code/Network/NetworkAPI/NetworkClient.cpp create mode 100644 Code/Network/NetworkAPI/NetworkClient.h rename Code/Network/{OysterNetworkServer/IServer.cpp => NetworkAPI/NetworkServer.cpp} (69%) create mode 100644 Code/Network/NetworkAPI/NetworkServer.h delete mode 100644 Code/Network/OysterNetworkServer/IClient.h delete mode 100644 Code/Network/OysterNetworkServer/IServer.h diff --git a/Code/Network/NetworkAPI/NetworkAPI.vcxproj b/Code/Network/NetworkAPI/NetworkAPI.vcxproj index adb00d01..8b0847b6 100644 --- a/Code/Network/NetworkAPI/NetworkAPI.vcxproj +++ b/Code/Network/NetworkAPI/NetworkAPI.vcxproj @@ -161,9 +161,18 @@ + + + + + + + + {c5aa09d0-6594-4cd3-bd92-1d380c7b3b50} + diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp new file mode 100644 index 00000000..062817c0 --- /dev/null +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -0,0 +1,41 @@ +#include "NetworkClient.h" + +using namespace Oyster::Network; + +/************************************* + PrivateData +*************************************/ + +struct PrivateData +{ + +}; + +/************************************* + NetworkClient +*************************************/ + +NetworkClient::NetworkClient() +{ + +} + +NetworkClient::~NetworkClient() +{ + +} + +void NetworkClient::Disconnect() +{ + +} + +bool NetworkClient::IsConnected() +{ + return false; +} + +void NetworkClient::Send() +{ + +} \ No newline at end of file diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h new file mode 100644 index 00000000..108cf83f --- /dev/null +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -0,0 +1,42 @@ +#ifndef NETWORK_API_NETWORK_CLIENT_H +#define NETWORK_API_NETWORK_CLIENT_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#ifdef CUSTOM_NET_PROTOCOL_EXPORT + #define NET_PROTOCOL_EXPORT __declspec(dllexport) +#else + #define NET_PROTOCOL_EXPORT __declspec(dllimport) +#endif + +class RecieverObject; + +namespace Oyster +{ + namespace Network + { + extern "C" + { + class NET_PROTOCOL_EXPORT NetworkClient + { + public: + NetworkClient(); + virtual ~NetworkClient(); + + virtual void Disconnect(); + virtual bool IsConnected(); + + virtual void Send(); + + private: + struct PrivateData; + PrivateData* privateData; + + }; + } + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/IServer.cpp b/Code/Network/NetworkAPI/NetworkServer.cpp similarity index 69% rename from Code/Network/OysterNetworkServer/IServer.cpp rename to Code/Network/NetworkAPI/NetworkServer.cpp index 84da54ba..05e72679 100644 --- a/Code/Network/OysterNetworkServer/IServer.cpp +++ b/Code/Network/NetworkAPI/NetworkServer.cpp @@ -1,7 +1,9 @@ -#include "IServer.h" +#include "NetworkServer.h" +#include "NetworkClient.h" + #include "../NetworkDependencies/Listener.h" -#include "IClient.h" #include "../NetworkDependencies/PostBox.h" + #include "../../Misc/Utilities.h" #include "../../Misc/Thread/OysterThread.h" @@ -14,7 +16,7 @@ using namespace Oyster::Thread; PrivateData *************************************/ -struct IServer::PrivateData : public IThreadObject +struct NetworkServer::PrivateData : public IThreadObject { PrivateData(); ~PrivateData(); @@ -41,19 +43,19 @@ struct IServer::PrivateData : public IThreadObject }; -IServer::PrivateData::PrivateData() +NetworkServer::PrivateData::PrivateData() { listener = 0; started = false; postBox = new PostBox; } -IServer::PrivateData::~PrivateData() +NetworkServer::PrivateData::~PrivateData() { Shutdown(); } -bool IServer::PrivateData::Init(INIT_DESC& initDesc) +bool NetworkServer::PrivateData::Init(INIT_DESC& initDesc) { //Check if it's a valid port if(initDesc.port == 0) @@ -72,7 +74,7 @@ bool IServer::PrivateData::Init(INIT_DESC& initDesc) return true; } -bool IServer::PrivateData::Start() +bool NetworkServer::PrivateData::Start() { //Start listener ((Listener*)listener)->Start(); @@ -83,7 +85,7 @@ bool IServer::PrivateData::Start() return true; } -bool IServer::PrivateData::Stop() +bool NetworkServer::PrivateData::Stop() { if(listener) { @@ -97,7 +99,7 @@ bool IServer::PrivateData::Stop() return true; } -bool IServer::PrivateData::Shutdown() +bool NetworkServer::PrivateData::Shutdown() { //Stop server main thread thread.Stop(); @@ -120,7 +122,7 @@ bool IServer::PrivateData::Shutdown() } //Checks for new clients and sends them to the proc function. -void IServer::PrivateData::CheckForNewClient() +void NetworkServer::PrivateData::CheckForNewClient() { if(postBox->IsFull()) { @@ -133,13 +135,16 @@ void IServer::PrivateData::CheckForNewClient() return; } - //Create the new client - IClient* client = new IClient(); - initDesc.proc(client); + //Create client and Proc function if the pointer is not NULL + if(initDesc.proc) + { + Oyster::Network::NetworkClient* client = new Oyster::Network::NetworkClient(); + initDesc.proc((NetworkClient*)client); + } } } -bool IServer::PrivateData::DoWork() +bool NetworkServer::PrivateData::DoWork() { CheckForNewClient(); @@ -147,15 +152,15 @@ bool IServer::PrivateData::DoWork() } /************************************* - IServer + NetworkServer *************************************/ -IServer::IServer() +NetworkServer::NetworkServer() { privateData = new PrivateData(); } -IServer::~IServer() +NetworkServer::~NetworkServer() { if(privateData) { @@ -163,35 +168,35 @@ IServer::~IServer() } } -bool IServer::Init(INIT_DESC& initDesc) +bool NetworkServer::Init(INIT_DESC& initDesc) { privateData->Init(initDesc); return true; } -bool IServer::Start() +bool NetworkServer::Start() { privateData->Start(); return true; } -bool IServer::Stop() +bool NetworkServer::Stop() { privateData->Stop(); return true; } -bool IServer::Shutdown() +bool NetworkServer::Shutdown() { privateData->Shutdown(); return true; } -bool IServer::IsStarted() const +bool NetworkServer::IsStarted() const { return privateData->started; } \ No newline at end of file diff --git a/Code/Network/NetworkAPI/NetworkServer.h b/Code/Network/NetworkAPI/NetworkServer.h new file mode 100644 index 00000000..427edab7 --- /dev/null +++ b/Code/Network/NetworkAPI/NetworkServer.h @@ -0,0 +1,56 @@ +#ifndef NETWORK_API_NETWORK_SERVER_H +#define NETWORK_API_NETWORK_SERVER_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#ifdef CUSTOM_NET_PROTOCOL_EXPORT + #define NET_PROTOCOL_EXPORT __declspec(dllexport) +#else + #define NET_PROTOCOL_EXPORT __declspec(dllimport) +#endif + +#pragma comment(lib, "ws2_32.lib") + +//#include "NetworkClient.h" + +namespace Oyster +{ + namespace Network + { + namespace Server + { + extern "C" + { + class NET_PROTOCOL_EXPORT NetworkServer + { + public: + class NetworkClient; + struct INIT_DESC + { + unsigned short port; //Port the server should be accepting clients on. + void (*proc)(NetworkClient*); + }; + + NetworkServer(); + virtual ~NetworkServer(); + + virtual bool Init(INIT_DESC& initDesc); + virtual bool Start(); + virtual bool Stop(); + virtual bool Shutdown(); + + virtual bool IsStarted() const; + + private: + struct PrivateData; + PrivateData* privateData; + + }; + } + } + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 299f60d3..5929ea7f 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -135,9 +135,9 @@ int Connection::Recieve(Utility::DynamicMemory::SmartPointer &bytes) int Connection::Listen() { int clientSocket; - if((clientSocket = accept(this->socket, NULL, NULL)) == INVALID_SOCKET) + if((clientSocket = (int)accept(this->socket, NULL, NULL)) == INVALID_SOCKET) { - return INVALID_SOCKET;//WSAGetLastError(); + return (int)INVALID_SOCKET;//WSAGetLastError(); } return clientSocket; @@ -148,7 +148,7 @@ int Connection::Listen() /////////////////////////////////////// int Connection::InitiateSocket() { - this->socket = ::socket(AF_INET, SOCK_STREAM, 0); + this->socket = (int)::socket(AF_INET, SOCK_STREAM, 0); if(this->socket == SOCKET_ERROR) { return WSAGetLastError(); diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp index 36cc4c83..a8443deb 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp @@ -130,7 +130,7 @@ void MessageHeader::PackDouble(double i, OysterByte& bytes) void MessageHeader::PackStr(char str[], OysterByte& bytes) { - int totalSize = 2 + strlen(str); + int totalSize = 2 + (int)strlen(str); bytes.AddSize(totalSize); Packing::Pack(&bytes.GetByteArray()[size], str); size += totalSize; @@ -138,7 +138,7 @@ void MessageHeader::PackStr(char str[], OysterByte& bytes) void MessageHeader::PackStr(std::string str, OysterByte& bytes) { - int totalSize = 2 + str.length(); + int totalSize = 2 + (int)str.length(); bytes.AddSize(totalSize); Packing::Pack(&bytes.GetByteArray()[size], str); size += totalSize; @@ -243,7 +243,7 @@ double MessageHeader::UnpackDouble(OysterByte& bytes) std::string MessageHeader::UnpackStr(OysterByte& bytes) { std::string str = Packing::UnpackStr(&bytes.GetByteArray()[size]); - size += 2 + str.length(); + size += 2 + (int)str.length(); return str; } diff --git a/Code/Network/NetworkDependencies/OysterByte.cpp b/Code/Network/NetworkDependencies/OysterByte.cpp index a0883604..db343e29 100644 --- a/Code/Network/NetworkDependencies/OysterByte.cpp +++ b/Code/Network/NetworkDependencies/OysterByte.cpp @@ -21,7 +21,7 @@ OysterByte::OysterByte(const OysterByte& obj) //delete[] this->byteArray; this->byteArray = new unsigned char[obj.capacity]; - for(int i = 0; i < obj.size; i++) + for(int i = 0; i < (int)obj.size; i++) { this->byteArray[i] = obj.byteArray[i]; } @@ -85,7 +85,7 @@ OysterByte& OysterByte::operator =(const OysterByte& obj) delete[] this->byteArray; this->byteArray = new unsigned char[obj.capacity]; - for(int i = 0; i < obj.size; i++) + for(int i = 0; i < (int)obj.size; i++) { this->byteArray[i] = obj.byteArray[i]; } diff --git a/Code/Network/NetworkDependencies/Packing.cpp b/Code/Network/NetworkDependencies/Packing.cpp index 192700b6..405cd5e6 100644 --- a/Code/Network/NetworkDependencies/Packing.cpp +++ b/Code/Network/NetworkDependencies/Packing.cpp @@ -100,7 +100,7 @@ namespace Oyster //string void Pack(unsigned char buffer[], char str[]) { - short len = strlen(str); + short len = (short)strlen(str); Pack(buffer, len); buffer += 2; memcpy(buffer, str, len); @@ -108,7 +108,7 @@ namespace Oyster void Pack(unsigned char buffer[], std::string& str) { - short len = str.length(); + short len = (short)str.length(); Pack(buffer, len); buffer += 2; memcpy(buffer, str.c_str(), len); diff --git a/Code/Network/NetworkDependencies/WinsockFunctions.cpp b/Code/Network/NetworkDependencies/WinsockFunctions.cpp index ea3c3b00..1ad0f89a 100644 --- a/Code/Network/NetworkDependencies/WinsockFunctions.cpp +++ b/Code/Network/NetworkDependencies/WinsockFunctions.cpp @@ -24,7 +24,7 @@ std::wstring GetErrorMessage(int errorCode) (LPWSTR)&lpMessage, 0 , NULL ); - + if(bufLen) { retVal = lpMessage; diff --git a/Code/Network/OysterNetworkServer/IClient.h b/Code/Network/OysterNetworkServer/IClient.h deleted file mode 100644 index 5b7fafe9..00000000 --- a/Code/Network/OysterNetworkServer/IClient.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef OYSTER_NETWORK_SERVER_I_CLIENT_H -#define OYSTER_NETWORK_SERVER_I_CLIENT_H - -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -class IClient -{ -public: - IClient() {} - virtual ~IClient() {} - - virtual void Disconnect() {} - virtual bool IsConnected() {return true;} - - virtual void Send() {} - -private: - -}; - -#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/IServer.h b/Code/Network/OysterNetworkServer/IServer.h deleted file mode 100644 index 0f34fdc3..00000000 --- a/Code/Network/OysterNetworkServer/IServer.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef OYSTER_NETWORK_SERVER_I_SERVER_H -#define OYSTER_NETWORK_SERVER_I_SERVER_H - -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "IClient.h" - -namespace Oyster -{ - namespace Network - { - namespace Server - { - class IServer - { - public: - struct INIT_DESC - { - unsigned short port; //Port the server should be accepting clients on. - void (*proc)(IClient*); - }; - - IServer(); - virtual ~IServer(); - - virtual bool Init(INIT_DESC& initDesc); - virtual bool Start(); - virtual bool Stop(); - virtual bool Shutdown(); - - virtual bool IsStarted() const; - - private: - struct PrivateData; - PrivateData* privateData; - - }; - } - } -} - -#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj index 82cec50e..4452ee37 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj @@ -149,18 +149,18 @@ {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + + {460d625f-2ac9-4559-b809-0ba89ceaedf4} + {c5aa09d0-6594-4cd3-bd92-1d380c7b3b50} - - - diff --git a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters index 23947d8a..6073a0c5 100644 --- a/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters +++ b/Code/Network/OysterNetworkServer/OysterNetworkServer.vcxproj.filters @@ -18,20 +18,11 @@ Source Files - - Source Files - Source Files - - Header Files - - - Header Files - Header Files diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index ce8e2742..f97aeb98 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -3,71 +3,24 @@ #include #include #include "../NetworkDependencies/WinsockFunctions.h" -#include "../NetworkDependencies/Listener.h" -#include "../NetworkDependencies/Translator.h" -#include "../NetworkDependencies/ThreadedClient.h" -#include "../NetworkDependencies/OysterByte.h" -#include "../NetworkDependencies/PostBox.h" -#include "../../Misc/WinTimer.h" -#include "../../Misc/Utilities.h" -#include "../../Misc/Utilities-Impl.h" - #include "TestClass.h" -#include "IServer.h" -#include "IClient.h" - -#pragma comment(lib, "ws2_32.lib") using namespace std; -using namespace Oyster::Network::Server; -using namespace Oyster::Network; -using namespace ::Protocols; -using namespace Utility; -using namespace ::Utility::DynamicMemory; -void clientProc(IClient* client); +void clientProc(Oyster::Network::NetworkClient* client); int main() { - Test tests; - - SmartPointer sendBuffer = new OysterByte; - SmartPointer recvBuffer = new OysterByte; - ProtocolSet* set = new ProtocolSet; - - cout << "Server" << endl; - Translator t; - int errorCode = 0; - if(!InitWinSock()) { cout << "errorMessage: unable to start winsock" << endl; } - IServer server; - IServer::INIT_DESC initDesc; - initDesc.port = 9876; - initDesc.proc = clientProc; - server.Init(initDesc); - server.Start(); + Test test; - Sleep(1000); + cout << "Server" << endl; - //Create a test protocol - ProtocolPlayerPos test; - test.clientID = 0; - test.ID = 5; - test.nrOfFloats = 10; - test.matrix = new float[test.nrOfFloats]; - - for(int i = 0; i < (int)test.nrOfFloats; i++) - { - test.matrix[i] = (float)i; - } - - t.Pack(test, sendBuffer); - - WinTimer timer; + test.mainLoop(); while(1) { @@ -92,21 +45,11 @@ int main() //PrintOutMessage(set); set->Release(); }*/ - - Sleep(1); } - server.Stop(); - server.Shutdown(); - //listener.Shutdown(); + Sleep(1000); system("pause"); return 0; -} - -void clientProc(IClient* client) -{ - cout << "Proc" << endl; - clients.push_back(client); } \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/TestClass.cpp b/Code/Network/OysterNetworkServer/TestClass.cpp index ec50bf9e..1580b644 100644 --- a/Code/Network/OysterNetworkServer/TestClass.cpp +++ b/Code/Network/OysterNetworkServer/TestClass.cpp @@ -3,6 +3,7 @@ #include using namespace Oyster::Network; +using namespace ::Server; using namespace ::Protocols; using namespace Utility; using namespace ::DynamicMemory; @@ -11,12 +12,35 @@ using namespace std; Test::Test() { recvPostBox = new PostBox>; + + sendBuffer = new OysterByte; + recvBuffer = new OysterByte; + + NetworkServer::INIT_DESC initDesc; + initDesc.port = 9876; + initDesc.proc = NULL; + server.Init(initDesc); + server.Start(); + + test.clientID = 0; + test.ID = 5; + test.nrOfFloats = 10; + test.matrix = new float[test.nrOfFloats]; + + for(int i = 0; i < (int)test.nrOfFloats; i++) + { + test.matrix[i] = (float)i; + } + + t.Pack(test, sendBuffer); } Test::~Test() { for(int i = 0; i < (int)clients.size(); i++) delete clients.at(i); + + server.Stop(); } void Test::ProcFunc(Utility::DynamicMemory::SmartPointer msg) diff --git a/Code/Network/OysterNetworkServer/TestClass.h b/Code/Network/OysterNetworkServer/TestClass.h index e3edf31f..439e5b1f 100644 --- a/Code/Network/OysterNetworkServer/TestClass.h +++ b/Code/Network/OysterNetworkServer/TestClass.h @@ -5,7 +5,8 @@ #include "../../Misc/Utilities.h" #include "../NetworkDependencies/OysterByte.h" #include "../NetworkDependencies/PostBox.h" -#include "IClient.h" +#include "../NetworkAPI/NetworkClient.h" +#include "../NetworkAPI/NetworkServer.h" #include "../NetworkDependencies/Translator.h" #include @@ -21,13 +22,15 @@ public: void PrintOutMessage(Oyster::Network::Protocols::ProtocolSet* set); private: - std::vector clients; + std::vector clients; Oyster::Network::IPostBox> *recvPostBox; Oyster::Network::Translator t; - Oyster::Network::Protocols::ProtocolPlayerPos test; + Utility::DynamicMemory::SmartPointer sendBuffer; + Utility::DynamicMemory::SmartPointer recvBuffer; + Oyster::Network::Server::NetworkServer server; };