DAVID4 SDK  1.8.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
david::TcpClient Class Reference

Implementation of a TCP client. More...

#include <TcpClient.h>

Public Member Functions

 TcpClient (const std::string &serverAddress, uint16_t serverPort)
 Constructor. More...
 
virtual ~TcpClient ()
 Destructor.
 
bool Connect ()
 Connect to the remote machine. More...
 
void Close ()
 Close socket.
 
std::string GetServerAddress () const
 Get remote IP address. More...
 
uint16_t GetServerPort () const
 Get remote port. More...
 
int64_t ReceiveString (std::string &data)
 Receive data from the network. More...
 
bool ReceiveBinary (void *data, size_t numBytes)
 Receive binary data from the network. More...
 
int64_t SendString (const std::string &data)
 Send data. More...
 
bool SendBinary (const void *data, size_t numBytes)
 Send binary data to network. More...
 

Detailed Description

Implementation of a TCP client.

Definition at line 38 of file TcpClient.h.

Constructor & Destructor Documentation

david::TcpClient::TcpClient ( const std::string &  serverAddress,
uint16_t  serverPort 
)

Constructor.

Parameters
[in]serverAddressRemote IP address. Use 127.0.0.1 for localhost.
[in]serverPortRemote port.

Member Function Documentation

bool david::TcpClient::Connect ( )

Connect to the remote machine.

True if successful, false otherwise.

std::string david::TcpClient::GetServerAddress ( ) const

Get remote IP address.

Returns
Server IP address.
uint16_t david::TcpClient::GetServerPort ( ) const

Get remote port.

Returns
Server port.
bool david::TcpClient::ReceiveBinary ( void *  data,
size_t  numBytes 
)

Receive binary data from the network.

Note
This method will block until 'numBytes' were received.
Parameters
[out]dataDestination buffer with size of at least 'numBytes'.
[in]numBytesNumber of bytes to be received.
Returns
True, if 'numBytes' were received.
int64_t david::TcpClient::ReceiveString ( std::string &  data)

Receive data from the network.

Function blocks until data is received.

Parameters
[out]dataGets the received data.
Returns
Number of bytes received or -1 in case of an error.
bool david::TcpClient::SendBinary ( const void *  data,
size_t  numBytes 
)

Send binary data to network.

Note
This method will block until 'numBytes' bytes are send.
Parameters
[in]dataSource buffer with size of at least 'numBytes'.
[in]numBytesNumber of bytes to be send.
Returns
True, if 'numBytes' were send.
int64_t david::TcpClient::SendString ( const std::string &  data)

Send data.

Parameters
[in]dataData to be sent.
Returns
Number of bytes sent or -1 in case of an error.

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