ipv4_udp_server.cpp
This is an example of how to use the 
Conexus::IPv4::UDP class.
#include <conexus.h>
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
#include <glibmm.h>
void print_data1(const Conexus::Data d);
void print_data2(const Conexus::Data d);
void print_data3(const Conexus::Data d);
int main(int argc, char* argv[]) {
  Glib::ustring interface;
  int port = 1500;
  int run_time = 20;
  Glib::OptionContext option_context( "- IPv4 UDP Server" );
  Glib::OptionGroup option_group( "Options", "" );
  Glib::OptionEntry option_interface;
  option_interface.set_long_name( "if" );
  option_interface.set_description( "Interface address to receive data on [ default = any ]" );
  option_group.add_entry( option_interface, interface );
  Glib::OptionEntry option_port;
  option_port.set_long_name( "port" );
  option_port.set_description( "Port to receive data on [default=1500]" );
  option_group.add_entry( option_port, port );
  Glib::OptionEntry option_run_time;
  option_run_time.set_long_name( "run" );
  option_run_time.set_description( "Running time in seconds [default=20]" );
  option_group.add_entry( option_run_time, run_time );
  option_context.set_main_group( option_group );
  option_context.parse( argc, argv );
  
  
  
  Conexus::init();
  
  Conexus::IPv4::UDP::pointer udp;
  if ( interface.size() == 0 )
    udp = Conexus::IPv4::UDP::create(port);
  else
    udp = Conexus::IPv4::UDP::create(interface, port);
  
  
  udp->signal_data().connect(sigc::ptr_fun(&print_data1));
  udp->signal_data().connect(sigc::ptr_fun(&print_data2));
  udp->signal_data().connect(sigc::ptr_fun(&print_data3));
  
  
  
  udp->start();
  std::cout << "Main thread pid: " << pthread_self() << std::endl;
  
  
  
  std::cout << "Starting..." << std::endl;
  std::cout << "Run time: " << run_time << std::endl;
  for (int i=0; i <= run_time; i++) {
    if (i%5 == 0)
      std::cout << "Time: " << i << std::endl;
    sleep(1);
  }
  std::cout << "Time: " << run_time << std::endl;
  
  udp->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.hex_string() << "]\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.hex_string() << "]\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.hex_string() << "]\n";
}