diff --git a/Code/Network/NetworkDependencies/Listener.cpp b/Code/Network/NetworkDependencies/Listener.cpp index e1b8fa08..c441d045 100644 --- a/Code/Network/NetworkDependencies/Listener.cpp +++ b/Code/Network/NetworkDependencies/Listener.cpp @@ -4,6 +4,7 @@ using namespace Oyster::Network::Server; Listener::Listener() { + connection = NULL; } Listener::~Listener() diff --git a/Code/Network/NetworkDependencies/Listener.h b/Code/Network/NetworkDependencies/Listener.h index 5888aed9..8bb16a0f 100644 --- a/Code/Network/NetworkDependencies/Listener.h +++ b/Code/Network/NetworkDependencies/Listener.h @@ -25,8 +25,7 @@ namespace Oyster bool Init(unsigned int port); void Shutdown(); - int Accept(); - int GetNewClient(); + void SetPostBox(IPostBox* postBox); //Thread functions @@ -35,6 +34,8 @@ namespace Oyster void ThreadExit(); private: + //Function that runs in the thread. + int Accept(); private: diff --git a/Code/Network/NetworkDependencies/OysterByte.h b/Code/Network/NetworkDependencies/OysterByte.h index 390e4398..87a0103c 100644 --- a/Code/Network/NetworkDependencies/OysterByte.h +++ b/Code/Network/NetworkDependencies/OysterByte.h @@ -30,8 +30,6 @@ namespace Oyster operator char*(); operator const char*(); operator unsigned char*(); - - //unsigned char& operator[](unsigned int id); private: void IncreaseCapacity(unsigned int cap); //Expands the byteArray diff --git a/Code/Network/NetworkDependencies/PostBox.h b/Code/Network/NetworkDependencies/PostBox.h index 6b2c2ff8..b2e553f8 100644 --- a/Code/Network/NetworkDependencies/PostBox.h +++ b/Code/Network/NetworkDependencies/PostBox.h @@ -13,6 +13,8 @@ namespace Oyster { namespace Network { + //With this class you can post items to it and then fetch them somewhere else. + //It is thread safe beacause of the ThreadSafeQueue. template class PostBox : public IPostBox { diff --git a/Code/Network/NetworkDependencies/Protocols.h b/Code/Network/NetworkDependencies/Protocols.h index f90d99c6..12444e3e 100644 --- a/Code/Network/NetworkDependencies/Protocols.h +++ b/Code/Network/NetworkDependencies/Protocols.h @@ -41,6 +41,9 @@ namespace Oyster virtual ~ProtocolTest() { delete[] f; } }; + + //Holding every protocol in an union. + //Used because we now don't have to type case our protocol when we recieve them. class ProtocolSet { public: diff --git a/Code/Network/NetworkDependencies/WinsockFunctions.h b/Code/Network/NetworkDependencies/WinsockFunctions.h index 92c8957a..a4edf38d 100644 --- a/Code/Network/NetworkDependencies/WinsockFunctions.h +++ b/Code/Network/NetworkDependencies/WinsockFunctions.h @@ -4,8 +4,8 @@ ///////////////////////////////////// // Created by Pontus Fransson 2013 // ///////////////////////////////////// -#include +#include void ShutdownWinSock(); bool InitWinSock(); diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index cc2e398b..9dd0a0c1 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -37,6 +37,7 @@ int main() listener.Init(9876); listener.SetPostBox(postBox); Sleep(1000); + //Start listening //Accept a client ProtocolTest test; @@ -84,37 +85,9 @@ int main() } listener.Shutdown(); - -/* int clientSocket = listener.Accept(); - Client client1(clientSocket); - cout << "First client connected." << endl; - - //Accept a client - clientSocket = listener.Accept(); - Client client2(clientSocket); - cout << "Second client connected." << endl; -*/ - - /* ProtocolSet* set = new ProtocolSet; - ProtocolTest test; - test.clientID = 0; - test.size = 2; - test.textMessage = "hej"; - test.numOfFloats = 35; - test.f = new float[test.numOfFloats]; - float temp = 395.456f; - for(int i = 0; i < (int)test.numOfFloats; i++) - { - test.f[i] = temp; - temp--; - } - t.Pack(test, recvBuffer);*/ - - -/* client1.Send(recvBuffer); while(1)