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; };