This Example shows how to send multi records with TR-UDP and get ACK event from remote peer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TACKM_VERSION "0.0.2"
#define CMD_U_STAT "stat"
#define CMD_U_RESET "reset"
#define CMD_U_DATA_OR_STAT "data_or_stat"
#define SERVER_NAME "none"
const char*
PRESS_A =
"(Press A to return to main application menu)";
enum {
size_t data_len, void *user_data) {
switch(event) {
printf("Connecting to peer: %s ...\n", peer_to);
else
printf("Server mode\n");
break;
{
printf("Peer %s connected at %s:%d \n",
}
break;
{
printf(
"Peer %s was disconnected \n", rd->
from);
}
else printf("Peer was disconnected\n");
}
break;
{
int i, idx, num_packets, command = *(int*)data;
switch(command) {
case '0':
ev_break (ke->
ev_loop, EVBREAK_ONE);
break;
case '1':
printf("How much package to send (0 - to exit): ");
if(scanf("%d", &num_packets));
printf("Send %d messages to %s\n",num_packets, peer_to);
idx = 0;
for(i = 0; i < num_packets; i++) {
sprintf(buffer, "#%d: Teoack Hello!", ++idx);
printf("Send message \"%s\"\n", buffer);
}
printf("\nACK ID: ");
break;
case '2':
break;
case '3':
(char*)peer_to,
break;
case '4':
{
if(arp != NULL) {
struct sockaddr_in remaddr;
socklen_t addrlen = sizeof(remaddr);
if(!
make_addr(arp->addr, arp->port, (__SOCKADDR_ARG) &remaddr, &addrlen)) {
trudpChannelData *tcd = trudpGetChannel(ke->
kc->
ku, (__CONST_SOCKADDR_ARG)&remaddr, addrlen, 0);
if((tcd != (void*)-1) && (tcd != NULL)) {
trudp_ChannelSendReset(tcd);
}
}
}
}
break;
case '5':
{
ksnet_arp_data *arp_data = (ksnet_arp_data *)
ksnetArpGet(ke->
kc->
ka, peer_to);
if(arp_data != NULL) {
struct sockaddr_in remaddr;
socklen_t addrlen = sizeof(remaddr);
if(!
make_addr(arp_data->addr, arp_data->port, (__SOCKADDR_ARG) &remaddr, &addrlen)) {
);
(char*)peer_to,
command, strlen(command) + 1
);
}
}
}
break;
default:
break;
}
}
}
break;
{
printf("\n"
"Multi send test menu:\n"
"\n"
" 1 - send packets\n"
" 2 - show TR-UDP statistics\n"
" 3 - get and show remote peer TR-UDP statistics\n"
" 4 - send TR-UDP reset\n"
" 5 - show data or TR-UDP statistic screen at server (now: %s)\n"
" 0 - exit\n"
"\n"
"teoackm $ "
);
fflush(stdout);
}
}
}
break;
{
printf(
"Got DATA: %s\n", (
char*)rd->
data);
}
break;
{
char *stat = ksnTRUDPstatShowStr(ke->
kc->
ku, 0);
}
sscanf((
char*)rd->
data,
"%*s %d",
printf("show_data_or_statistic_at_server %d\n",
}
else {
}
}
}
break;
break;
}
}
break;
{
printf("%d ", *(uint32_t*)user_data);
fflush(stdout);
}
}
break;
default:
break;
}
}
int main(
int argc,
char** argv) {
printf(
"Teoack multi example ver " TACKM_VERSION ", based on teonet ver. "
const char *app_argv[] = { "", "peer_to"};
return (EXIT_SUCCESS);
}