From 5465ccf51abede2960935b6d0c8a238cde27b845 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 6 Dec 2013 10:45:53 +0100 Subject: [PATCH] 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