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

@ -48,10 +48,12 @@ ThreadedClient::~ThreadedClient()
} }
} }
int ThreadedClient::Send(SmartPointer<OysterByte> &byte) int ThreadedClient::Send(SmartPointer<OysterByte>& byte)
{ {
SmartPointer<OysterByte> temp = new OysterByte(*byte);
mutex.LockMutex(); mutex.LockMutex();
this->sendPostBox->PostMessage(byte); this->sendPostBox->PostMessage(temp);
mutex.UnlockMutex(); mutex.UnlockMutex();
return 0; return 0;
} }
@ -62,9 +64,9 @@ int ThreadedClient::Send()
mutex.LockMutex(); mutex.LockMutex();
if(sendPostBox->IsFull()) if(sendPostBox->IsFull())
{ {
SmartPointer<OysterByte> temp = NULL; //SmartPointer<OysterByte> temp = NULL;
sendPostBox->FetchMessage(temp); //sendPostBox->FetchMessage(temp);
errorCode = this->connection->Send(temp); //errorCode = this->connection->Send(temp);
} }
mutex.UnlockMutex(); mutex.UnlockMutex();
@ -75,7 +77,7 @@ int ThreadedClient::Recv()
{ {
int errorCode = 0; int errorCode = 0;
SmartPointer<OysterByte> temp = new OysterByte(); /*SmartPointer<OysterByte> temp = new OysterByte();
errorCode = this->connection->Recieve(temp); errorCode = this->connection->Recieve(temp);
if(errorCode == 0) if(errorCode == 0)
@ -84,7 +86,7 @@ int ThreadedClient::Recv()
recvPostBox->PostMessage(temp); recvPostBox->PostMessage(temp);
mutex.UnlockMutex(); mutex.UnlockMutex();
} }
*/
return errorCode; return errorCode;
} }

View File

@ -24,7 +24,7 @@ namespace Oyster
ThreadedClient(IPostBox<Utility::DynamicMemory::SmartPointer< OysterByte >> *postBox, unsigned int socket); ThreadedClient(IPostBox<Utility::DynamicMemory::SmartPointer< OysterByte >> *postBox, unsigned int socket);
virtual ~ThreadedClient(); virtual ~ThreadedClient();
int Send(Utility::DynamicMemory::SmartPointer< OysterByte > &byte); int Send(Utility::DynamicMemory::SmartPointer< OysterByte >& byte);
int Connect(unsigned short port, const char serverName[]); int Connect(unsigned short port, const char serverName[]);

View File

@ -59,8 +59,8 @@ void chat(ThreadedClient &client)
client.setRecvPostBox(postBox); client.setRecvPostBox(postBox);
SmartPointer<OysterByte> msgRecv = SmartPointer<OysterByte>(new OysterByte()); SmartPointer<OysterByte> msgRecv = new OysterByte();
SmartPointer<OysterByte> msgSend = SmartPointer<OysterByte>(new OysterByte()); SmartPointer<OysterByte> msgSend = new OysterByte();
ProtocolSet* set = new ProtocolSet; ProtocolSet* set = new ProtocolSet;
ProtocolPlayerPos test; 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> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="IServer.cpp" />
<ClCompile Include="ServerMain.cpp" /> <ClCompile Include="ServerMain.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ClInclude Include="IClient.h" />
<ClInclude Include="IServer.h" />
<ClInclude Include="ISession.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

View File

@ -18,5 +18,19 @@
<ClCompile Include="ServerMain.cpp"> <ClCompile Include="ServerMain.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </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> </ItemGroup>
</Project> </Project>

View File

@ -12,6 +12,9 @@
#include "../../Misc/Utilities.h" #include "../../Misc/Utilities.h"
#include "../../Misc/Utilities-Impl.h" #include "../../Misc/Utilities-Impl.h"
#include "IServer.h"
#include "ISession.h"
#pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "ws2_32.lib")
using namespace std; using namespace std;
@ -24,9 +27,15 @@ using namespace ::Utility::DynamicMemory;
void PrintOutMessage(ProtocolSet* set); void PrintOutMessage(ProtocolSet* set);
int main() int main()
{ {
SmartPointer<OysterByte> sendBuffer = SmartPointer<OysterByte>(new OysterByte); IServer server;
SmartPointer<OysterByte> recvBuffer = SmartPointer<OysterByte>(new OysterByte()); IServer::INIT_DESC initDesc;
server.Init(initDesc);
//Old program
SmartPointer<OysterByte> sendBuffer = new OysterByte;
SmartPointer<OysterByte> recvBuffer = new OysterByte();
ProtocolSet* set = new ProtocolSet; ProtocolSet* set = new ProtocolSet;
IPostBox<SmartPointer<int>> *postBox = new PostBox<SmartPointer<int>>(); IPostBox<SmartPointer<int>> *postBox = new PostBox<SmartPointer<int>>();
IPostBox<SmartPointer<OysterByte>> *recvPostBox = new PostBox<SmartPointer<OysterByte>>(); IPostBox<SmartPointer<OysterByte>> *recvPostBox = new PostBox<SmartPointer<OysterByte>>();
@ -64,7 +73,7 @@ int main()
WinTimer timer; WinTimer timer;
vector<ThreadedClient*> clients; vector<ThreadedClient*> clients;
SmartPointer<int> client = SmartPointer<int>(); SmartPointer<int> client = int();
while(1) while(1)
{ {
//Fetch new clients from the postbox //Fetch new clients from the postbox