This class implements the TCP/IP client communication. More...
#include <class_tcp.h>
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. | |
This class implements the TCP/IP client communication.
Definition at line 46 of file class_tcp.h.
| 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.
| 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.
| 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.
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.
Definition at line 80 of file class_tcp.cpp.
| int tcp_client::GetSocket | ( | ) |
Get socket value.
Get the current 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.
| text | additional text to print along with the 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.
| 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 |
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.
| data | information to send, this is a byte array | |
| size | size of the information to send |
Definition at line 97 of file class_tcp.cpp.
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.
| 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.