From d78b48319d9a77506702f1a07a6b26640d7ffc5b Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 3 Dec 2013 11:46:46 +0100 Subject: [PATCH 1/2] 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 10c1dc57f3c9235ca6c6d4e69fed43465daa7752 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Tue, 3 Dec 2013 13:08:04 +0100 Subject: [PATCH 2/2] 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);