Public Member Functions | Public Attributes | Private Attributes | List of all members
tcp_client Class Reference

This class implements the TCP/IP client communication. More...

#include <class_tcp.h>

Public Member Functions

int Connect (void)
 Connect to server. More...
 
int Disconnect (void)
 Disconnect from server. More...
 
int GetSocket ()
 Get socket value. More...
 
int perr (const char *text)
 Print error message. More...
 
int Receive (char *data, int size, bool peek=false, int *number=NULL, int flags=0)
 Read data. More...
 
int Send (char *data, int size)
 Send data. More...
 
 tcp_client (const char *ip, int port, bool async_comm=false)
 Constructor of the class. More...
 
 ~tcp_client ()
 Destructor of the class. More...
 

Public Attributes

bool connected
 Status of the connection. More...
 
int err
 Last error code. More...
 
char err_msg [1024]
 Last error message. More...
 

Private Attributes

bool async
 Asynchronous comm. More...
 
int ret
 Return value for functions. More...
 
struct sockaddr_in server
 Configuration structure. More...
 
int sock
 Socket identification. More...
 

Detailed Description

This class implements the TCP/IP client communication.

Definition at line 46 of file class_tcp.h.

Constructor & Destructor Documentation

tcp_client::tcp_client ( const char *  ip,
int  port,
bool  async_comm = false 
)

Constructor of the class.

The class constructor will setup the socket but will NOT open it.

Parameters
ipIp of the server
portPort in which to communicate
async_commActivate the asynchronous communication.

Definition at line 29 of file class_tcp.cpp.

tcp_client::~tcp_client ( )

Destructor of the class.

It disconnects the communication.

Definition at line 52 of file class_tcp.cpp.

Member Function Documentation

int tcp_client::Connect ( void  )

Connect to server.

This function connects to the server in case of error sets the err_msg variable and the err code accordingly.

Returns
0 in case of success or -1 in error

Definition at line 57 of file class_tcp.cpp.

int tcp_client::Disconnect ( void  )

Disconnect from server.

This function disconnects to the server in case of error sets the err_msg variable and the err code accordingly.

Returns
0 in case of success or -1 in error

Definition at line 80 of file class_tcp.cpp.

int tcp_client::GetSocket ( )

Get socket value.

Get the current socket value.

Returns
Socket value.

Definition at line 184 of file class_tcp.cpp.

int tcp_client::perr ( const char *  text)

Print error message.

This function prints the last error of this class, this is only valid for the last function called, if a function previous to that had a error it will not be printed.

Parameters
textadditional text to print along with the error.
Returns
0 if theres no error to print or -1 in error

Definition at line 174 of file class_tcp.cpp.

int tcp_client::Receive ( char *  data,
int  size,
bool  peek = false,
int *  number = NULL,
int  flags = 0 
)

Read data.

This function reads information from the memory buffer, if the peek variable is true the information is not erased from the buffer.

Parameters
datawhere to store the data
sizemaximum length to store
peekif true data is not removed from the server
numbernumber of bytes received
flagsflags of the recv call
Returns
0 in case of success or -1 in error

Definition at line 131 of file class_tcp.cpp.

int tcp_client::Send ( char *  data,
int  size 
)

Send data.

This function sends information to the server, in case of error sets the err_msg variable and the err code accordingly.

Parameters
datainformation to send, this is a byte array
sizesize of the information to send
Returns
0 in case of success or -1 in error

Definition at line 97 of file class_tcp.cpp.

Member Data Documentation

bool tcp_client::async
private

Asynchronous comm.

Definition at line 147 of file class_tcp.h.

bool tcp_client::connected

Status of the connection.

Definition at line 134 of file class_tcp.h.

int tcp_client::err

Last error code.

Definition at line 128 of file class_tcp.h.

char tcp_client::err_msg[1024]

Last error message.

Definition at line 131 of file class_tcp.h.

int tcp_client::ret
private

Return value for functions.

Definition at line 144 of file class_tcp.h.

struct sockaddr_in tcp_client::server
private

Configuration structure.

Definition at line 141 of file class_tcp.h.

int tcp_client::sock
private

Socket identification.

Definition at line 138 of file class_tcp.h.


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


tcp_client
Author(s): Jorge Almeida
autogenerated on Mon Mar 2 2015 01:32:53