This commit is contained in:
Pontus Fransson 2013-11-21 13:46:25 +01:00
commit 7c417dd223
17 changed files with 218 additions and 50 deletions

View File

@ -3,15 +3,7 @@
#include <winsock2.h>
#include <iostream>
Connection::Connection()
{
mySocket = NULL;
}
Connection::Connection(int socket)
{
mySocket = socket;
}
using namespace Oyster::Network;
Connection::~Connection()
{

View File

@ -7,23 +7,30 @@
#include "IConnection.h"
class Connection : public ::Oyster::Network::IConnection
namespace Oyster
{
private:
int mySocket;
namespace Network
{
class Connection : public IConnection
{
public:
Connection();
Connection(int socket);
~Connection();
public:
Connection() { mySocket = 0; };
Connection(int socket) { mySocket = socket; };
~Connection();
virtual bool Connect( unsigned short port , const char serverName[] );
virtual bool InitiateServer( unsigned short port );
virtual void Disconnect();
virtual bool Send(const char message[]);
virtual int Recieve(char message[]);
virtual int Listen();
virtual bool Connect( unsigned short port , const char serverName[] );
virtual bool InitiateServer( unsigned short port );
virtual void Disconnect();
virtual bool Send(const char message[]);
virtual int Recieve(char message[]);
virtual int Listen();
};
private:
int mySocket;
};
}
}
#endif

View File

@ -11,13 +11,14 @@ namespace Oyster
{
class IConnection
{
public:
virtual void Disconnect() = 0;
virtual bool Send( const char message[] ) = 0;
virtual int Recieve(char message[]) = 0;
virtual bool InitiateServer( unsigned short port ) { return false; };
virtual int Listen() { return -1; };
virtual bool Connect( unsigned short port, const char serverName[] ) { return false; };
public:
virtual void Disconnect() = 0;
virtual bool Send( const char message[] ) = 0;
virtual int Recieve(char message[]) = 0;
virtual bool InitiateServer( unsigned short port ) { return false; };
virtual int Listen() { return -1; };
virtual bool Connect( unsigned short port, const char serverName[] ) { return false; };
};
}
}

View File

@ -0,0 +1,18 @@
#ifndef NETWORK_DEPENDENCIES_I_TRANSLATE
#define NETWORK_DEPENDENCIES_I_TRANSLATE
namespace Oyster
{
namespace Network
{
class ITranslate
{
public:
virtual char* Translate (const Protocols::ProtocolHeader &header ) = 0;
virtual Protocols::ProtocolHeader& Translate ( char message[] ) = 0;
};
}
}
#endif

View File

@ -156,6 +156,7 @@
<ClCompile Include="Messages\MessageHeader.cpp" />
<ClCompile Include="Messages\MessageTest.cpp" />
<ClCompile Include="Packing.cpp" />
<ClCompile Include="Translator.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Connection.h" />
@ -163,6 +164,9 @@
<ClInclude Include="Messages\MessageHeader.h" />
<ClInclude Include="Messages\MessageTest.h" />
<ClInclude Include="Packing.h" />
<ClInclude Include="ITranslate.h" />
<ClInclude Include="Protocols.h" />
<ClInclude Include="Translator.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -28,6 +28,7 @@
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Messages\MessageTest.cpp">
<ClCompile Include="Translator.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
@ -45,6 +46,13 @@
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Messages\MessageHeader.h">
<ClInclude Include="Protocols.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ITranslate.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Translator.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>

View File

@ -0,0 +1,35 @@
#include "string";
namespace Oyster
{
namespace Network
{
namespace Protocols
{
enum PackageType
{
package_type_header,
package_type_test,
package_type_input,
package_type_update_position
};
struct ProtocolHeader
{
int size;
int packageType;
int clientID;
ProtocolHeader() { this->packageType = package_type_header; }
};
struct ProtocolTest : public ProtocolHeader
{
std::string textMessage;
ProtocolTest() { this->packageType = package_type_test; }
};
}
}
}

View File

@ -0,0 +1,50 @@
//#include "Translator.h"
//
//using namespace Oyster::Network;
//using namespace ::Protocols;
//using namespace ::Messages;
//
//char* Translate ( const ProtocolHeader &header )
//{
// MessageHeader *message;
//
// switch(header.packageType)
// {
//
// case package_type_header:
// message = new MessageHeader();
// break;
//
// case package_type_test:
// message = new MessageTest();
// break;
// }
//
// message->Translate(header);
// return message->GetMsg();
//}
//
//ProtocolHeader& Translator::Translate( char msg[] )
//{
// ProtocolHeader header;
// MessageHeader *message = new MessageHeader();
//
// header = message->translate(message);
//
// switch(header.packageType)
// {
//
// case package_type_header:
// message = new MessageHeader();
// break;
//
// case package_type_test:
// message = new MessageTest();
// break;
// }
//
// message->Translate(msg);
// return message->GetProtocol();
//}

View File

@ -0,0 +1,27 @@
//#ifndef NETWORK_DEPENDENCIES_TRANSLATOR_H
//#define NETWORK_DEPENDENCIES_TRANSLATOR_H
//
////#include "MessageHeader.h"
//#include "Protocols.h"
//#include "ITranslate.h"
//
//namespace Oyster
//{
// namespace Network
// {
// namespace Messages
// {
// class Translator
// {
// public:
// Translator (){};
// ~Translator(){};
//
// char* Translate (const Protocols::ProtocolHeader &header );
// Protocols::ProtocolHeader& Translate ( char msg[] );
// };
// }
// }
//}
//
//#endif

View File

@ -1,5 +1,7 @@
#include "Client.h"
using namespace Oyster::Network::Client;
Client::Client()
{
connection = new Connection();

View File

@ -7,20 +7,28 @@
#include "../NetworkDependencies/Connection.h"
class Client
namespace Oyster
{
public:
Client();
~Client();
namespace Network
{
namespace Client
{
class Client
{
public:
Client();
~Client();
bool Connect(unsigned int port, char filename[]);
bool Connect(unsigned int port, char filename[]);
void Send(char msg[]);
void Recv(char msg[]);
void Send(char msg[]);
void Recv(char msg[]);
private:
Connection* connection;
};
private:
::Oyster::Network::Connection* connection;
};
}
}
}
#endif

View File

@ -2,6 +2,7 @@
#include "Client.h"
#include <WinSock2.h>
using namespace std;
using namespace Oyster::Network::Client;
#pragma comment(lib, "ws2_32.lib")
void ShutdownSockets();

View File

@ -1,5 +1,7 @@
#include "Client.h"
using namespace Oyster::Network::Server;
Client::Client(unsigned int socket)
{
connection = new Connection(socket);

View File

@ -7,18 +7,28 @@
#include "../NetworkDependencies/Connection.h"
class Client
namespace Oyster
{
public:
Client(unsigned int socket);
~Client();
namespace Network
{
namespace Server
{
class Client
{
void Send(char buffer[]);
void Recv(char buffer[]);
public:
Client(unsigned int socket);
~Client();
private:
Connection* connection;
void Send(char buffer[]);
void Recv(char buffer[]);
private:
::Oyster::Network::Connection* connection;
};
}
}
};
#endif

View File

@ -1,5 +1,7 @@
#include "Listener.h"
using namespace Oyster::Network;
Listener::Listener()
{

View File

@ -18,7 +18,7 @@ public:
int Accept();
private:
Connection* connection;
::Oyster::Network::Connection* connection;
};

View File

@ -3,6 +3,7 @@
#include "Listener.h"
#include "Client.h"
using namespace std;
using namespace Oyster::Network::Server;
#pragma comment(lib, "ws2_32.lib")