Connection class, responsible of send/receive data from any client or server. Regardless its communication protocol or synchrony.

#include <tcpServer.h>

Inheritance diagram for TcpConnection:

Public Types

typedef boost::shared_ptr< TcpConnectionpointer
 Pointer to TCP connection.
 

Public Member Functions

boost::asio::ip::tcp::socket & socket ()
 Boost TCP socket. More...
 
bool isDisconnected ()
 returns if it is disconected More...
 
void disconnect ()
 Disconnect function for TCP socket.
 
void write (std::string sendData)
 Function responsible of send the data through the socket. More...
 
void receive ()
 Asynchronous receiving.
 
void setWriteStatusHandler (boost::function< void(const boost::system::error_code &error, std::size_t size)> writeStatusHandler)
 To set the write handler. More...
 
void setReceiveSendHandler (boost::function< void(const boost::system::error_code &error, const char *receiveData, std::string &sendData)> receiveSendHandler)
 To set the read handler. More...
 

Static Public Member Functions

static pointer create (boost::asio::io_context &io_context)
 Static function to create the boost share object of Connection related to an io context. It is one way to hide the Connection class only available for Server class. More...
 

Member Function Documentation

static pointer create ( boost::asio::io_context &  io_context)
static
Parameters
io_contextThe service for the connection.
Returns
The share object.
bool isDisconnected ( )
Returns
true if it is disconected
void setReceiveSendHandler ( boost::function< void(const boost::system::error_code &error, const char *receiveData, std::string &sendData)>  receiveSendHandler)
Parameters
receiveSendHandlerThe read handler to send data.
void setWriteStatusHandler ( boost::function< void(const boost::system::error_code &error, std::size_t size)>  writeStatusHandler)
Parameters
writeStatusHandlerThe write handler to call when finish.
boost::asio::ip::tcp::socket& socket ( )
Returns
socketBoost TCP socket.
void write ( std::string  sendData)
Parameters
sendDataThe data to send.