TCP/IP client library usage

How to use the TCP/IP client library?

Include and link

Include the main header for the library.

#include <tcp_client/class_tcp.h>

Add to the manifest the dependency.

<depend package="tcp_client"/>

This two steps should be enough to compile and link with the library.

Class declaration

First create the object and initialize it.

tcp_client comm("192.168.1.100",1000);

The class constructor will setup the socket but will NOT open it. The first argument of the constructor is the IP of the server and the second the port number to use.
The class can also be used in asynchronous communications by using the following constructor:

tcp_client comm("192.168.1.100",1000,true);

The user is responsible for the interception of communication signals (SIGIO) and its handling.

Using the class

Class usage is very simple, the user must only class the desired function to Send() or Receive() data.

char output_message[1024];
char input_message[1024];

memset(output_message,0,sizeof(output_message));
memset(input_message,0,sizeof(input_message));

strcpy(output_message,"I'm alive");

comm.Send(output_message,strlen(output_message));
comm.perr("Could not send message");

if(!comm.err)
printf("Message \"%s\", sent successfully\n",output_message); 

comm.Receive(input_message,sizeof(input_message));
comm.perr("Could not receive message");

if(!comm.err)
printf("Message \"%s\", received\n",input_message); 
 All Classes Files Functions Variables


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