The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
MHA_TCP::Client Class Reference

A portable class for a tcp client connections. More...

Inheritance diagram for MHA_TCP::Client:
Inheritance graph

Public Member Functions

 Client (const std::string &host, unsigned short port)
 Constructor connects to host, port via TCP. More...
 
 Client (const std::string &host, unsigned short port, Timeout_Watcher &timeout_watcher)
 Constructor connects to host, port via TCP, using a timeout. More...
 
- Public Member Functions inherited from MHA_TCP::Connection
Sockread_Eventget_read_event ()
 
Sockwrite_Eventget_write_event ()
 
std::string get_peer_address ()
 Get peer's IP Address. More...
 
unsigned short get_peer_port ()
 Get peer's TCP port. More...
 
SOCKET get_fd () const
 Return the (protected) file descriptor of the connection. More...
 
virtual ~Connection ()
 Destructor closes the underlying file descriptor. More...
 
bool eof ()
 Checks if the peer has closed the connection. More...
 
bool can_read_line (char delim='\n')
 Checks if a full line of text has arrived by now. More...
 
bool can_read_bytes (unsigned howmany)
 Checks if the specified ammount of data can be read. More...
 
std::string read_line (char delim='\n')
 Reads a single line of data from the socket. More...
 
std::string read_bytes (unsigned howmany)
 Reads the specified ammount of dat from the socket. More...
 
void try_write (const std::string &data="")
 Adds data to the internal "outgoing" buffer, and then tries to write as much data from that buffer to the socket as possible without blocking. More...
 
void write (const std::string &data="")
 Adds data to the internal "outgoing" buffer, and then writes that that buffer to the socket, regardless of blocking. More...
 
bool needs_write ()
 Checks if the internal "outgoing" buffer contains data. More...
 
unsigned buffered_incoming_bytes () const
 Returns the number of bytes in the internal "incoming" buffer. More...
 
unsigned buffered_outgoing_bytes () const
 Returns the number of bytes in the internal "outgoing" buffer. More...
 

Additional Inherited Members

- Protected Member Functions inherited from MHA_TCP::Connection
 Connection (SOCKET _fd)
 Create a connection instance from a socket filedescriptor. More...
 
- Protected Attributes inherited from MHA_TCP::Connection
SOCKET fd
 The file descriptor of the TCP Socket. More...
 

Detailed Description

A portable class for a tcp client connections.

Constructor & Destructor Documentation

◆ Client() [1/2]

Client::Client ( const std::string &  host,
unsigned short  port 
)

Constructor connects to host, port via TCP.

Parameters
hostThe hostname of the TCP Server.
portThe port or the TCP Server.

◆ Client() [2/2]

Client::Client ( const std::string &  host,
unsigned short  port,
Timeout_Watcher timeout_watcher 
)

Constructor connects to host, port via TCP, using a timeout.

Parameters
hostThe hostname of the TCP Server.
portThe port or the TCP Server.
timeout_watcheran Event watcher that implements a timeout.

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