Async  1.3.1
Public Member Functions | Public Attributes | List of all members
Async::TcpClient Class Reference

A class for creating a TCP client connection. More...

#include <AsyncTcpClient.h>

Inheritance diagram for Async::TcpClient:
Async::TcpConnection

Public Member Functions

 TcpClient (size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
 Constructor. More...
 
 TcpClient (const std::string &remote_host, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
 Constructor. More...
 
 TcpClient (const IpAddress &remote_ip, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
 Constructor. More...
 
 ~TcpClient (void)
 Destructor. More...
 
void bind (const IpAddress &bind_ip)
 Bind to the interface having the specified IP address. More...
 
void connect (const std::string &remote_host, uint16_t remote_port)
 Connect to the remote host. More...
 
void connect (const Async::IpAddress &remote_ip, uint16_t remote_port)
 Connect to the remote host. More...
 
void connect (void)
 Connect to the remote host. More...
 
void disconnect (void)
 Disconnect from the remote host. More...
 
bool isIdle (void) const
 Check if the connection is idle. More...
 
- Public Member Functions inherited from Async::TcpConnection
 TcpConnection (size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
 Constructor. More...
 
 TcpConnection (int sock, const IpAddress &remote_addr, uint16_t remote_port, size_t recv_buf_len=DEFAULT_RECV_BUF_LEN)
 Constructor. More...
 
 ~TcpConnection (void)
 Destructor. More...
 
void setRecvBufLen (size_t recv_buf_len)
 Set a new receive buffer size. More...
 
void disconnect (void)
 Disconnect from the remote host. More...
 
int write (const void *buf, int count)
 Write data to the TCP connection. More...
 
const IpAddressremoteHost (void) const
 Return the IP-address of the remote host. More...
 
uint16_t remotePort (void) const
 Return the remote port used. More...
 
bool isConnected (void) const
 Check if the connection is established or not. More...
 
bool isIdle (void) const
 Check if the connection is idle. More...
 

Public Attributes

sigc::signal< void > connected
 A signal that is emitted when a connection has been established. More...
 
- Public Attributes inherited from Async::TcpConnection
sigc::signal< void, TcpConnection *, DisconnectReasondisconnected
 A signal that is emitted when a connection has been terminated. More...
 
sigc::signal< int, TcpConnection *, void *, int > dataReceived
 A signal that is emitted when data has been received on the connection. More...
 
sigc::signal< void, bool > sendBufferFull
 A signal that is emitted when the send buffer status changes. More...
 

Additional Inherited Members

- Public Types inherited from Async::TcpConnection
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 Public Member Functions inherited from Async::TcpConnection
static const char * disconnectReasonStr (DisconnectReason reason)
 Translate disconnect reason to a string. More...
 
- Static Public Attributes inherited from Async::TcpConnection
static const int DEFAULT_RECV_BUF_LEN = 1024
 The default length of the reception buffer. More...
 
- Protected Member Functions inherited from Async::TcpConnection
void setSocket (int sock)
 Setup information about the connection. More...
 
void setRemoteAddr (const IpAddress &remote_addr)
 Setup information about the connection. More...
 
void setRemotePort (uint16_t remote_port)
 Setup information about the connection. More...
 
int socket (void) const
 Return the socket file descriptor. More...
 

Detailed Description

A class for creating a TCP client connection.

Author
Tobias Blomberg
Date
2003-04-12

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.

Constructor & Destructor Documentation

Async::TcpClient::TcpClient ( size_t  recv_buf_len = DEFAULT_RECV_BUF_LEN)
explicit

Constructor.

Parameters
recv_buf_lenThe 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. When using this variant of the constructor the connect method which take host and port must be used.

Async::TcpClient::TcpClient ( const std::string &  remote_host,
uint16_t  remote_port,
size_t  recv_buf_len = DEFAULT_RECV_BUF_LEN 
)

Constructor.

Parameters
remote_hostThe hostname of the remote host
remote_portThe port on the remote host to connect to
recv_buf_lenThe 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 ( const IpAddress remote_ip,
uint16_t  remote_port,
size_t  recv_buf_len = DEFAULT_RECV_BUF_LEN 
)

Constructor.

Parameters
remote_ipThe IP address of the remote host
remote_portThe port on the remote host to connect to
recv_buf_lenThe 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.

Member Function Documentation

void Async::TcpClient::bind ( const IpAddress bind_ip)

Bind to the interface having the specified IP address.

Parameters
bind_ipThe IP address of the interface to bind to
void Async::TcpClient::connect ( const std::string &  remote_host,
uint16_t  remote_port 
)

Connect to the remote host.

Parameters
remote_hostThe hostname of the remote host
remote_portThe port on the remote host to connect to

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::connect ( const Async::IpAddress remote_ip,
uint16_t  remote_port 
)

Connect to the remote host.

Parameters
remote_ipThe IP address of the remote host
remote_portThe port on the remote host to connect to

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::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

bool Async::TcpClient::isIdle ( void  ) const
inline

Check if the connection is idle.

Returns
Returns true if the connection is idle

A connection being idle means that it is not connected nor connecting.

Definition at line 231 of file AsyncTcpClient.h.

References Async::TcpConnection::isIdle().

Member Data Documentation

sigc::signal<void> Async::TcpClient::connected

A signal that is emitted when a connection has been established.

Definition at line 236 of file AsyncTcpClient.h.


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