Async
0.18.0
|
A class for creating a TCP client connection. More...
#include <AsyncTcpClient.h>
Public Member Functions | |
TcpClient (const std::string &remote_host, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
~TcpClient (void) | |
Destructor. | |
void | connect (void) |
Connect to the remote host. | |
void | disconnect (void) |
Disconnect from the remote host. | |
![]() | |
TcpConnection (size_t recv_buf_len=DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
TcpConnection (int sock, const IpAddress &remote_addr, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN) | |
Constructor. | |
~TcpConnection (void) | |
Destructor. | |
void | disconnect (void) |
Disconnect from the remote host. | |
int | write (const void *buf, int count) |
Write data to the TCP connection. | |
const IpAddress & | remoteHost (void) const |
Return the IP-address of the remote host. | |
uint16_t | remotePort (void) const |
Return the remote port used. | |
bool | isConnected (void) const |
Check if the connection is established or not. | |
Public Attributes | |
SigC::Signal0< void > | connected |
A signal that is emitted when a connection has been established. | |
![]() | |
SigC::Signal2< void, TcpConnection *, DisconnectReason > | disconnected |
A signal that is emitted when a connection has been terminated. | |
SigC::Signal3< int, TcpConnection *, void *, int > | dataReceived |
A signal that is emitted when data has been received on the connection. | |
SigC::Signal1< void, bool > | sendBufferFull |
A signal that is emitted when the send buffer status changes. | |
Additional Inherited Members | |
![]() | |
enum | DisconnectReason { DR_HOST_NOT_FOUND, DR_REMOTE_DISCONNECTED, DR_SYSTEM_ERROR, DR_RECV_BUFFER_OVERFLOW, DR_ORDERED_DISCONNECT } |
Reason code for disconnects. More... | |
![]() | |
static const char * | disconnectReasonStr (DisconnectReason reason) |
Translate disconnect reason to a string. | |
![]() | |
static const int | DEFAULT_RECV_BUF_LEN = 1024 |
The default length of the reception buffer. | |
![]() | |
void | setSocket (int sock) |
Setup information about the connection. | |
void | setRemoteAddr (const IpAddress &remote_addr) |
Setup information about the connection. | |
void | setRemotePort (uint16_t remote_port) |
Setup information about the connection. | |
int | socket (void) const |
Return the socket file descriptor. | |
A class for creating a TCP client connection.
This class is used to create a TCP client connection. All details of how to create the connection is hidden inside the class. This make it very easy to create and use the connections. An example usage is shown below.
Definition at line 130 of file AsyncTcpClient.h.
Async::TcpClient::TcpClient | ( | const std::string & | remote_host, |
uint16_t | remote_port, | ||
size_t | recv_buf_len = DEFAULT_RECV_BUF_LEN |
||
) |
Constructor.
remote_host | The hostname of the remote host |
remote_port | The port on the remote host to connect to |
recv_buf_len | The length of the receiver buffer to use |
The object will be constructed and variables will be initialized but no connection will be created until the connect function (see TcpClient::connect) is called.
Async::TcpClient::~TcpClient | ( | void | ) |
Destructor.
void Async::TcpClient::connect | ( | void | ) |
Connect to the remote host.
This function will initiate a connection to the remote host. The connection must not be written to before the connected signal (see TcpClient::connected) has been emitted. If the connection is already established or pending, nothing will be done.
void Async::TcpClient::disconnect | ( | void | ) |
Disconnect from the remote host.
Call this function to disconnect from the remote host. If already disconnected, nothing will be done. The disconnected signal is not emitted when this function is called
SigC::Signal0<void> Async::TcpClient::connected |
A signal that is emitted when a connection has been established.
Definition at line 173 of file AsyncTcpClient.h.