Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
teosend.c

Send and receive teonet messages

Test application to send and receive teonet messages.

How to execute this test:

1) Start one teonet test application in terminal:

 tests/teosend teosend -p 9500

2) Start another test application in other terminal:

 tests/teosend teorecv -r 9500 -a 127.0.0.1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ev_mgr.h"
#define TSEND_VERSION VERSION
size_t data_len, void *user_data) {
switch(event) {
// Send immediately after event manager starts
printf("Event: Event manager started\n");
//host_started_cb(ke);
break;
// Send when new peer connected to this host (and to the mesh)
printf("Event: Peer '%s' was connected\n", ((ksnCorePacketData*)data)->from);
break;
printf("Event: Peer '%s' was disconnected\n", ((ksnCorePacketData*)data)->from);
break;
// Send when data received
{
printf("Event: Data received %d bytes\n", (int)data_len);
//host_received_cb(ke, data, data_len);
printf("Command: %d, Data: %s, got from: %s\n", rd->cmd, (char*)rd->data, rd->from);
}
break;
// Send when idle (every 11.5 sec idle time)
case EV_K_IDLE:
printf("Event: Idle time\n");
//host_idle_cb(ke);
break;
// Send by timer
case EV_K_TIMER:
{
const char *teorecv = "teorecv";
if(strcmp(teorecv, ksnetEvMgrGetHostName(ke))) {
ksnCoreSendCmdto(ke->kc, (char*)teorecv, CMD_USER, "Hello!", 7);
}
}
break;
// Undefined event (an error)
default:
break;
}
}
int main(int argc, char** argv) {
printf("Teosend ver " TSEND_VERSION "\n");
// Initialize teonet event manager and Read configuration
// Set custom timer interval
// Hello message
ksnet_printf(&ke->teo_cfg, MESSAGE, "Started...\n\n");
// Start teonet
return (EXIT_SUCCESS);
}