ipv4_udpposet_server.cpp
This example server demonstrates receiving on three ports using
Conexus::IPv4::UDPPoset.
#include <conexus.h>
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
void print_data1(const Conexus::Data d);
void print_data2(const Conexus::Data d);
void print_data3(const Conexus::Data d);
int main() {
Conexus::init();
Conexus::IPv4::UDP::pointer udp1 = Conexus::IPv4::UDP::create(1500);
Conexus::IPv4::UDP::pointer udp2 = Conexus::IPv4::UDP::create(1501);
Conexus::IPv4::UDP::pointer udp3 = Conexus::IPv4::UDP::create(1502);
udp1->signal_data().connect(sigc::ptr_fun(&print_data1));
udp2->signal_data().connect(sigc::ptr_fun(&print_data2));
udp3->signal_data().connect(sigc::ptr_fun(&print_data3));
udp1->start();
udp2->start();
udp3->start();
std::cout << "Main thread pid: " << pthread_self() << std::endl;
std::cout << "Starting..." << std::endl;
for (int i=1; i <= 20; i++) {
if (i%5 == 0)
std::cout << "Time: " << i << std::endl;
sleep(1);
}
udp1->stop();
udp2->stop();
udp3->stop();
return 0;
}
void print_data1(const Conexus::Data d) {
std::cout << "Responding thread pid: " << pthread_self() << std::endl;
std::cout << "<1> Received " << d.size() << " bytes of data [" << d.data() << "]\n";
}
void print_data2(const Conexus::Data d) {
std::cout << "Responding thread pid: " << pthread_self() << std::endl;
std::cout << "<2> Received " << d.size() << " bytes of data [" << d.data() << "]\n";
}
void print_data3(const Conexus::Data d) {
std::cout << "Responding thread pid: " << pthread_self() << std::endl;
std::cout << "<3> Received " << d.size() << " bytes of data [" << d.data() << "]\n";
}