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

Get ACK event

This Example shows how to get ACK event from remote peer

Created on August 14, 2015, 1:53 PM

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ev_mgr.h"
#define TACK_VERSION "0.0.2"
size_t data_len, void *user_data) {
switch(event) {
// Calls immediately after event manager starts
break;
// Send by timer
case EV_K_TIMER:
{
static int idx = 0;
char buffer[KSN_BUFFER_DB_SIZE];
char *peer_to = ke->teo_cfg.app_argv[1]; //"tr-udp-11";
if(strcmp(peer_to, ksnetEvMgrGetHostName(ke))) {
// If peer_to is connected
if (ksnetArpGet(ke->kc->ka, peer_to) != NULL) {
sprintf(buffer, "#%d: Teoack Hello!", idx++);
printf("\nSend message \"%s\" to %s peer\n", buffer, peer_to);
ksnCoreSendCmdto(ke->kc, (char*)peer_to, CMD_USER, buffer,
strlen(buffer)+1);
ksnetEvMgrSetCustomTimer(ke, 0.00); // Stop timer
}
}
}
break;
// Teo ACK received use ksnetAllowAckEvent to allow this event
{
// Got ACK event
printf("Got ACK event to ID %d, data: %s\n",
*(uint32_t*)user_data, (char*)rd->data);
ksnetEvMgrSetCustomTimer(ke, 1.00); // Set custom timer interval
}
break;
// Undefined event (an error)
default:
break;
}
}
int main(int argc, char** argv) {
printf("Teoack example ver " TACK_VERSION ", based on teonet ver. " VERSION "\n");
// Application parameters
const char *app_argv[] = { "", "peer_to"};
ksnetEvMgrAppParam app_param;
app_param.app_argc = 2;
app_param.app_argv = app_argv;
app_param.app_descr = NULL;
// Initialize teonet event manager and Read configuration
// Set custom timer interval
// Allow ACK event
// Start teonet
return (EXIT_SUCCESS);
}