Using the Teonet Subscribe module
Module: subscribe.c This is example application to subscribe one teonet application to other teonet application event. This application has code for two type of applications: server and client. Client subscribed to server and get EV_K_SUBSCRIBE event when event happen at the server application.
Start applications:
- start one application as server:
examples/teosscr teosscr-ser null
- start other application as client:
examples/teosscr teosscr-cli teosscr-ser -r 9000 -a 127.0.0.1
In client application use:
- teoSScrSubscribe() function to subscribe to remote peer event
- case EV_K_SUBSCRIBE in event loop to get event when event happen at the remote peer
In server application use:
Only the EV_K_CONNECTED, EV_K_DISCONNECTED, EV_K_L0_CONNECTED and EV_K_L0_DISCONNECTED events sent automatically by the teonet library. All other events should be described and send by applications provided this events from its event callback function.
Created on January 5, 2016, 3:38 PM
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TSSCR_VERSION "0.0.1"
static int app_type = 0;
size_t data_len, void *user_data) {
switch(event) {
{
printf("The peer: '%s' was connected\n", peer);
}
}
break;
{
"Hello!", 7);
}
break;
{
teoSScrData *ssrc_data = rd->
data;
printf("EV_K_SUBSCRIBE received from: %s, event: %d, command: %d, "
"from: %s, data: %s\n",
rd->
from, ssrc_data->ev, ssrc_data->cmd, ssrc_data->data,
ssrc_data->data + strlen(ssrc_data->data) + 1 );
}
break;
default:
break;
}
}
size_t data_len, void *user_data) {
switch(event) {
{
printf(
"Peer %s was disconnected \n", rd->
from);
}
else printf("Peer was disconnected\n");
}
break;
{
printf("EV_K_RECEIVED command: %d, from %s, data: %s\n",
char *rec_data =
malloc(rec_data_len);
}
}
break;
default:
break;
}
}
size_t data_len, void *user_data) {
switch(event) {
{
printf("Type of this application: ");
printf("Client peer subscribed to '%s' peer\n",
app_type = 0;
}
else {
printf("Server peer to subscribe to\n");
app_type = 1;
}
}
break;
default:
break;
}
}
int main(
int argc,
char** argv) {
"based on teonet ver. " VERSION "\n");
const char *app_argv[] = { "", "remote_peer"};
return (EXIT_SUCCESS);
}