2013-11-25 11:39:38 +01:00
|
|
|
#ifndef NETWORK_DEPENDENCIES_I_CONNECTION_H
|
|
|
|
#define NETWORK_DEPENDENCIES_I_CONNECTION_H
|
|
|
|
|
2013-11-19 12:38:13 +01:00
|
|
|
//////////////////////////////////
|
|
|
|
// Created by Sam Svensson 2013 //
|
|
|
|
//////////////////////////////////
|
|
|
|
|
2014-02-17 10:38:11 +01:00
|
|
|
#include "Utilities.h"
|
2013-12-04 12:40:49 +01:00
|
|
|
|
2013-11-19 13:42:50 +01:00
|
|
|
namespace Oyster
|
2013-11-19 12:38:13 +01:00
|
|
|
{
|
2013-11-19 13:42:50 +01:00
|
|
|
namespace Network
|
|
|
|
{
|
2014-01-29 15:01:14 +01:00
|
|
|
struct ConnectionInfo
|
|
|
|
{
|
|
|
|
int socket;
|
|
|
|
std::string addr;
|
|
|
|
};
|
|
|
|
|
2013-11-27 11:01:22 +01:00
|
|
|
class OysterByte;
|
2013-11-19 13:42:50 +01:00
|
|
|
class IConnection
|
|
|
|
{
|
2013-11-21 13:40:52 +01:00
|
|
|
|
|
|
|
public:
|
2013-11-29 09:18:58 +01:00
|
|
|
|
|
|
|
//sends and recieve functions with bytearrays,
|
|
|
|
//will send to the users connection via socket
|
2013-12-13 23:47:16 +01:00
|
|
|
virtual int Send( OysterByte &bytes ) = 0;
|
|
|
|
virtual int Recieve( OysterByte &bytes) = 0;
|
2013-11-29 09:18:58 +01:00
|
|
|
|
|
|
|
//initiates sockets and address for server and client
|
2013-11-26 13:45:03 +01:00
|
|
|
virtual int InitiateServer( unsigned short port ) { return false; };
|
|
|
|
virtual int InitiateClient() { return false; };
|
2013-11-29 09:18:58 +01:00
|
|
|
|
|
|
|
//Listen function to let client connect, only used by the server
|
2014-01-29 15:01:14 +01:00
|
|
|
virtual ConnectionInfo Listen() { return ConnectionInfo(); };
|
2013-11-29 09:18:58 +01:00
|
|
|
|
|
|
|
//enables the client to connect with a server with use of name and port
|
|
|
|
//(servers uses Listen instead of connect)
|
2013-11-26 13:45:03 +01:00
|
|
|
virtual int Connect( unsigned short port, const char serverName[] ) { return false; };
|
2013-11-29 09:18:58 +01:00
|
|
|
|
2014-02-19 09:25:40 +01:00
|
|
|
//Tries to connect with the same port and ip used for Connect.
|
|
|
|
virtual int Reconnect() = 0;
|
|
|
|
|
2013-11-29 09:18:58 +01:00
|
|
|
//Disconnects the client or server TODO: optimize!
|
|
|
|
virtual int Disconnect() = 0;
|
2013-11-19 13:42:50 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2013-11-19 12:38:13 +01:00
|
|
|
|
|
|
|
#endif
|