Network - Started implementing Server,client,session.

This commit is contained in:
Pontus Fransson 2013-12-06 10:45:53 +01:00
parent df1594a43b
commit 5465ccf51a
10 changed files with 180 additions and 14 deletions

View File

@ -50,8 +50,10 @@ ThreadedClient::~ThreadedClient()
int ThreadedClient::Send(SmartPointer<OysterByte>& byte)
{
SmartPointer<OysterByte> 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<OysterByte> temp = NULL;
sendPostBox->FetchMessage(temp);
errorCode = this->connection->Send(temp);
//SmartPointer<OysterByte> temp = NULL;
//sendPostBox->FetchMessage(temp);
//errorCode = this->connection->Send(temp);
}
mutex.UnlockMutex();
@ -75,7 +77,7 @@ int ThreadedClient::Recv()
{
int errorCode = 0;
SmartPointer<OysterByte> temp = new OysterByte();
/*SmartPointer<OysterByte> 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;
}

View File

@ -59,8 +59,8 @@ void chat(ThreadedClient &client)
client.setRecvPostBox(postBox);
SmartPointer<OysterByte> msgRecv = SmartPointer<OysterByte>(new OysterByte());
SmartPointer<OysterByte> msgSend = SmartPointer<OysterByte>(new OysterByte());
SmartPointer<OysterByte> msgRecv = new OysterByte();
SmartPointer<OysterByte> msgSend = new OysterByte();
ProtocolSet* set = new ProtocolSet;
ProtocolPlayerPos test;

View File

@ -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

View File

@ -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)
{
}

View File

@ -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

View File

@ -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

View File

@ -154,8 +154,14 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="IServer.cpp" />
<ClCompile Include="ServerMain.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="IClient.h" />
<ClInclude Include="IServer.h" />
<ClInclude Include="ISession.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -18,5 +18,19 @@
<ClCompile Include="ServerMain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="IServer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="IServer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ISession.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="IClient.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -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;
@ -25,8 +28,14 @@ void PrintOutMessage(ProtocolSet* set);
int main()
{
SmartPointer<OysterByte> sendBuffer = SmartPointer<OysterByte>(new OysterByte);
SmartPointer<OysterByte> recvBuffer = SmartPointer<OysterByte>(new OysterByte());
IServer server;
IServer::INIT_DESC initDesc;
server.Init(initDesc);
//Old program
SmartPointer<OysterByte> sendBuffer = new OysterByte;
SmartPointer<OysterByte> recvBuffer = new OysterByte();
ProtocolSet* set = new ProtocolSet;
IPostBox<SmartPointer<int>> *postBox = new PostBox<SmartPointer<int>>();
IPostBox<SmartPointer<OysterByte>> *recvPostBox = new PostBox<SmartPointer<OysterByte>>();
@ -64,7 +73,7 @@ int main()
WinTimer timer;
vector<ThreadedClient*> clients;
SmartPointer<int> client = SmartPointer<int>();
SmartPointer<int> client = int();
while(1)
{
//Fetch new clients from the postbox