R-Type
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GameEngine::Network::ACommunication Class Referenceabstract

#include <ACommunication.hpp>

Inheritance diagram for GameEngine::Network::ACommunication:
RType::Client::UdpClient RType::Server::UdpServer

Public Member Functions

 ACommunication (asio::io_context &IOContext, unsigned short port)
 Abstract class that will handle communication. More...
 
virtual ~ACommunication ()
 
template<typename Socket , typename Endpoint >
void sendData (void *data, std::size_t size, uint8_t packetType, Socket &socket, Endpoint &endpoint)
 Set the header to send the value. More...
 
void sendInformation (void *data, std::size_t size, asio::ip::udp::socket &socket, asio::ip::udp::endpoint &endpoint, struct RType::Protocol::HeaderDataPacket &header)
 send the data to endpoint from the socket More...
 
void sendInformation (void *data, std::size_t size, asio::ip::tcp::socket &socket, asio::ip::tcp::endpoint &, struct RType::Protocol::HeaderDataPacket &header)
 send the data to endpoint from the socket More...
 
void handleReceive (const asio::error_code &error, std::size_t recvBytes, struct RType::Protocol::HeaderDataPacket &header)
 handle the header information More...
 
void readHeader ()
 read the header to retrieve informations More...
 

Protected Member Functions

virtual void handleData (struct RType::Protocol::HeaderDataPacket &, unsigned short port)=0
 function that will be set and used from derived class from this abstract More...
 

Protected Attributes

asio::streambuf _streamBuffer
 
asio::ip::udp::socket _udpSocket
 
asio::streambuf::mutable_buffers_type _buffer
 
struct RType::Protocol::HeaderDataPacket _header
 
asio::ip::udp::endpoint _endpoint
 
std::map< unsigned short, asio::ip::udp::endpoint > _listClient
 

Constructor & Destructor Documentation

◆ ACommunication()

GameEngine::Network::ACommunication::ACommunication ( asio::io_context &  IOContext,
unsigned short  port 
)

Abstract class that will handle communication.

Parameters
IOContextthat will be use to create our socket and asynchronous operation
portthat will the socket to bind

◆ ~ACommunication()

virtual GameEngine::Network::ACommunication::~ACommunication ( )
inlinevirtual

Member Function Documentation

◆ handleData()

virtual void GameEngine::Network::ACommunication::handleData ( struct RType::Protocol::HeaderDataPacket ,
unsigned short  port 
)
protectedpure virtual

function that will be set and used from derived class from this abstract

Implemented in RType::Server::UdpServer, and RType::Client::UdpClient.

◆ handleReceive()

void GameEngine::Network::ACommunication::handleReceive ( const asio::error_code &  error,
std::size_t  recvBytes,
struct RType::Protocol::HeaderDataPacket header 
)

handle the header information

Parameters
errorif asynchronous operation failed, will be checked
recvBytescorresponding to the ammount of bytes receive
headertype of data;

◆ readHeader()

void GameEngine::Network::ACommunication::readHeader ( )

read the header to retrieve informations

◆ sendData()

template<typename Socket , typename Endpoint >
void GameEngine::Network::ACommunication::sendData ( void *  data,
std::size_t  size,
uint8_t  packetType,
Socket &  socket,
Endpoint &  endpoint 
)
inline

Set the header to send the value.

Template Parameters
SocketTemplate that will be use for the socket (TCP, UDP)
EndpointTemplate that will be use as endpoint (TCP, UDP)
Parameters
datathat will be send
sizeof the data
packetTypethat will be used to identified the header
socketowner socket
endpointsending value to

◆ sendInformation() [1/2]

void GameEngine::Network::ACommunication::sendInformation ( void *  data,
std::size_t  size,
asio::ip::tcp::socket &  socket,
asio::ip::tcp::endpoint &  ,
struct RType::Protocol::HeaderDataPacket header 
)

send the data to endpoint from the socket

Parameters
datathat will be send
sizeof the data
socketowner of the sending message (Tcp)
endpointdata sending to
headerthat will determined the type of data

◆ sendInformation() [2/2]

void GameEngine::Network::ACommunication::sendInformation ( void *  data,
std::size_t  size,
asio::ip::udp::socket &  socket,
asio::ip::udp::endpoint &  endpoint,
struct RType::Protocol::HeaderDataPacket header 
)

send the data to endpoint from the socket

Parameters
datathat will be send
sizeof the data
socketowner of the sending message (Udp)
endpointdata sending to
headerthat will determined the type of data

Member Data Documentation

◆ _buffer

asio::streambuf::mutable_buffers_type GameEngine::Network::ACommunication::_buffer
protected

◆ _endpoint

asio::ip::udp::endpoint GameEngine::Network::ACommunication::_endpoint
protected

◆ _header

struct RType::Protocol::HeaderDataPacket GameEngine::Network::ACommunication::_header
protected

◆ _listClient

std::map<unsigned short, asio::ip::udp::endpoint> GameEngine::Network::ACommunication::_listClient
protected

◆ _streamBuffer

asio::streambuf GameEngine::Network::ACommunication::_streamBuffer
protected

◆ _udpSocket

asio::ip::udp::socket GameEngine::Network::ACommunication::_udpSocket
protected

The documentation for this class was generated from the following files: