tcp_client Class Reference

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

#include <class_tcp.h>

List of all members.

Public Member Functions

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

Public Attributes

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

Private Attributes

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

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:
ip Ip of the server
port Port in which to communicate
async_comm Activate 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:
text additional 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:
data where to store the data
size maximum length to store
peek if true data is not removed from the server
number number of bytes received
flags flags 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:
data information to send, this is a byte array
size size 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.

Status of the connection.

Definition at line 134 of file class_tcp.h.

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:
 All Classes Files Functions Variables


tcp_client
Author(s): Jorge Almeida
autogenerated on Wed Jul 23 04:34:44 2014