Network - Changed to CustomProtocolObject on send.

This commit is contained in:
Pontus Fransson 2013-12-12 10:32:43 +01:00
parent 04436258a5
commit 49cfbbebd5
5 changed files with 18 additions and 8 deletions

View File

@ -5,6 +5,8 @@
// Created by Dennis Andersen 2013 // // Created by Dennis Andersen 2013 //
///////////////////////////////////// /////////////////////////////////////
#include <memory>
namespace Oyster namespace Oyster
{ {
namespace Network namespace Network
@ -37,10 +39,16 @@ namespace Oyster
union RecieverObject union RecieverObject
{ {
ClientConnectCallbackMethod clientConnectFnc; ClientConnectCallbackMethod clientConnectFnc; // !< A function pointer for sending or recieving NetworkClient
ProtocolRecieverFunction protocolRecieverFnc; ProtocolRecieverFunction protocolRecieverFnc; // !< A function pointer for sending or recieving CustomNetProtocol
ClientConnectedObject *clientConnectObject; ClientConnectedObject *clientConnectObject; // !< An object for sending or recieving NetworkClient
ProtocolRecieverObject *protocolRecievedObject; ProtocolRecieverObject *protocolRecievedObject; // !< An object for sending or recieving CustomNetProtocol
RecieverObject() { memset(this, 0, sizeof(RecieverObject)); }
RecieverObject(ClientConnectCallbackMethod o) { clientConnectFnc = o; }
RecieverObject(ProtocolRecieverFunction o) { protocolRecieverFnc = o; }
RecieverObject(ClientConnectedObject* o) { clientConnectObject = o; }
RecieverObject(ProtocolRecieverObject* o) { protocolRecievedObject = o; }
}; };
} }
} }

View File

@ -233,9 +233,9 @@ bool NetworkClient::IsConnected()
return privateData->connection->IsConnected(); return privateData->connection->IsConnected();
} }
void NetworkClient::Send(CustomNetProtocol& protocol) void NetworkClient::Send(CustomProtocolObject& protocol)
{ {
this->privateData->Send(protocol); this->privateData->Send(*protocol.GetProtocol());
} }
void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type) void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type)

View File

@ -19,6 +19,7 @@ namespace Oyster
{ {
extern "C" extern "C"
{ {
struct CustomProtocolObject;
class NET_PROTOCOL_EXPORT NetworkClient class NET_PROTOCOL_EXPORT NetworkClient
{ {
public: public:
@ -33,7 +34,7 @@ namespace Oyster
bool IsConnected(); bool IsConnected();
void Send(CustomNetProtocol& protocol); void Send(CustomProtocolObject& protocol);
void SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type); void SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type);

View File

@ -8,6 +8,7 @@
#include "../NetworkDependencies/Messages/MessageHeader.h" #include "../NetworkDependencies/Messages/MessageHeader.h"
#include "../NetworkDependencies/OysterByte.h" #include "../NetworkDependencies/OysterByte.h"
using namespace Oyster::Network; using namespace Oyster::Network;
using namespace ::Messages; using namespace ::Messages;
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;

View File

@ -34,7 +34,7 @@ int main()
ThreadedClient* client = new ThreadedClient; ThreadedClient* client = new ThreadedClient;
//Connect to server //Connect to server
errorCode = client->Connect(9876, "localhost"); errorCode = client->Connect(15151, "193.11.186.101");
if(errorCode != 0) if(errorCode != 0)
{ {