SGCT master (487fac4)
Simple Graphics Cluster Toolkit
Loading...
Searching...
No Matches
sgct::Network Class Reference

Network manages peer-to-peer tcp connections. More...

#include <sgct/network.h>

Public Types

enum class  ConnectionType { SyncConnection , DataTransfer }

Public Member Functions

 Network (int port, const std::string &address, bool isServer, ConnectionType t)
 ~Network ()
void initialize ()
void closeNetwork (bool forced)
void initShutdown ()
void setDecodeFunction (std::function< void(const char *, int)> fn)
void setPackageDecodeFunction (std::function< void(void *, int, int, int)> fn)
void setUpdateFunction (std::function< void(Network &)> fn)
void setConnectedFunction (std::function< void(void)> fn)
void setAcknowledgeFunction (std::function< void(int, int)> fn)
void setConnectedStatus (bool state)
void closeSocket (SGCT_SOCKET lSocket)
ConnectionType type () const
int id () const
bool isServer () const
bool isConnected () const
int sendFrameCurrent () const
int recvFrameCurrent () const
int recvFramePrevious () const
double loopTime () const
 Get the time in seconds from send to receive of sync data.
bool isUpdated () const
 This function compares the received frame number with the sent frame number.
void sendData (const void *data, int length) const
int iterateFrameCounter ()
 Iterates the send frame number and returns the new frame number.
void pushClientMessage ()
 The client sends ack message to server + console messages.
int port () const
std::condition_variable & startConnectionConditionVar ()

Static Public Member Functions

static int lastError ()

Static Public Attributes

static constexpr char DefaultId = 0
static constexpr char Ack = 6
static constexpr char DataId = 17
static constexpr char ConnectedId = 18
static constexpr char DisconnectId = 19
static constexpr size_t HeaderSize = 13

Detailed Description

Network manages peer-to-peer tcp connections.

Member Enumeration Documentation

◆ ConnectionType

enum class sgct::Network::ConnectionType
strong
Enumerator
SyncConnection 
DataTransfer 

Constructor & Destructor Documentation

◆ Network()

sgct::Network::Network ( int port,
const std::string & address,
bool isServer,
ConnectionType t )
Parameters
portThe network port (TCP)
addressThe hostname, IPv4 address or IPv6 address
isServerIndicates if this connection is a server or client
tThe type of connection

◆ ~Network()

sgct::Network::~Network ( )

Member Function Documentation

◆ closeNetwork()

void sgct::Network::closeNetwork ( bool forced)

◆ closeSocket()

void sgct::Network::closeSocket ( SGCT_SOCKET lSocket)

◆ id()

int sgct::Network::id ( ) const

◆ initialize()

void sgct::Network::initialize ( )

◆ initShutdown()

void sgct::Network::initShutdown ( )

◆ isConnected()

bool sgct::Network::isConnected ( ) const

◆ isServer()

bool sgct::Network::isServer ( ) const

◆ isUpdated()

bool sgct::Network::isUpdated ( ) const

This function compares the received frame number with the sent frame number.

The server starts by sending a frame sync number to the client. The client receives the sync frame number and sends it back after drawing when ready for buffer swap. When the server gets a frame sync number equal to the sent number it swaps buffers.

Returns
true if updates has been received

◆ iterateFrameCounter()

int sgct::Network::iterateFrameCounter ( )

Iterates the send frame number and returns the new frame number.

◆ lastError()

int sgct::Network::lastError ( )
static
Returns
The last error code

◆ loopTime()

double sgct::Network::loopTime ( ) const

Get the time in seconds from send to receive of sync data.

◆ port()

int sgct::Network::port ( ) const
Returns
The port of this connection

◆ pushClientMessage()

void sgct::Network::pushClientMessage ( )

The client sends ack message to server + console messages.

◆ recvFrameCurrent()

int sgct::Network::recvFrameCurrent ( ) const

◆ recvFramePrevious()

int sgct::Network::recvFramePrevious ( ) const

◆ sendData()

void sgct::Network::sendData ( const void * data,
int length ) const

◆ sendFrameCurrent()

int sgct::Network::sendFrameCurrent ( ) const

◆ setAcknowledgeFunction()

void sgct::Network::setAcknowledgeFunction ( std::function< void(int, int)> fn)

◆ setConnectedFunction()

void sgct::Network::setConnectedFunction ( std::function< void(void)> fn)

◆ setConnectedStatus()

void sgct::Network::setConnectedStatus ( bool state)

◆ setDecodeFunction()

void sgct::Network::setDecodeFunction ( std::function< void(const char *, int)> fn)

◆ setPackageDecodeFunction()

void sgct::Network::setPackageDecodeFunction ( std::function< void(void *, int, int, int)> fn)

◆ setUpdateFunction()

void sgct::Network::setUpdateFunction ( std::function< void(Network &)> fn)

◆ startConnectionConditionVar()

std::condition_variable & sgct::Network::startConnectionConditionVar ( )

◆ type()

ConnectionType sgct::Network::type ( ) const

Member Data Documentation

◆ Ack

char sgct::Network::Ack = 6
staticconstexpr

◆ ConnectedId

char sgct::Network::ConnectedId = 18
staticconstexpr

◆ DataId

char sgct::Network::DataId = 17
staticconstexpr

◆ DefaultId

char sgct::Network::DefaultId = 0
staticconstexpr

◆ DisconnectId

char sgct::Network::DisconnectId = 19
staticconstexpr

◆ HeaderSize

size_t sgct::Network::HeaderSize = 13
staticconstexpr

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