#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ev.h>
#define TL0C_VERSION "0.0.1"
void tcp_read_cb(
struct ev_loop *loop,
struct ev_io *
w,
int revents) {
if(rc > 0) {
teoLNullCPacket *sp = (teoLNullCPacket*)buf;
switch(sp->cmd) {
{
char *
data = sp->peer_name + sp->peer_name_length;
"Receive %d bytes CMD_ECHO_ANSWER: %d bytes data from L0 server, "
"from peer %s, data: %s\n",
(int)rc, sp->data_length, sp->peer_name, data);
} break;
{
ksnet_arp_data_ar *data_ar = (void*) (sp->peer_name + sp->peer_name_length);
"Receive %d bytes CMD_PEERS_ANSWER: %d bytes data from L0 server, "
"from peer %s, data rows: %d\n",
(int)rc, sp->data_length, sp->peer_name, data_ar->length);
printf("%s", header);
int i = 0;
for(i = 0; i < data_ar->length; i++) {
&data_ar->arp_data[i].data);
printf("%s", str);
}
printf("%s", footer);
} break;
default:
"Receive %d bytes UNKNOWN_COMMAND %d: %d bytes data from L0 server, "
"from peer %s\n",
(int)rc, sp->cmd, sp->data_length, sp->peer_name);
break;
}
printf("Press Ctrl+C to exit\n");
}
}
size_t data_len, void *user_data) {
switch(event) {
{
printf("Start teonet L0 Client example\n");
teosockSetTcpNodelay(
fd);
ev_io_set (&
w,
fd, EV_READ);
teoLNullCPacket *pkg = (teoLNullCPacket*) packet;
size_t snd;
host_name);
if((snd = write(
fd, pkg, pkg_length)) >= 0);
"Send %d bytes initialize packet to L0 server\n", (int)snd);
if((snd = teoLNullPacketSend(
fd,
false, pkg, pkg_length)) >= 0);
"Send %d bytes packet to L0 server to peer %s, cmd = %d\n",
CMD_ECHO, peer_name, msg, strlen(msg) + 1);
if((snd = teoLNullPacketSend(
fd,
false, pkg, pkg_length)) >= 0);
"Send %d bytes packet to L0 server to peer %s, cmd = %d, data: %s\n",
}
} break;
default:
break;
}
}
int main(
int argc,
char** argv) {
"based on teonet ver. " VERSION "\n");
const char *app_argv[] = { "", "l0_server", "port", "peer_to", "message"};
return (EXIT_SUCCESS);
}