conexus logo

ipv4_udpposet_client.cpp

This example client demonstrates sending to three destinations using Conexus::IPv4::UDPPoset.

/***************************************************************************
 *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
 *   rvinyard@cs.nmsu.edu                                                  *
 *                                                                         *
 *   This file is part of the conexus library.                             *
 *                                                                         *
 *   The conexus library is free software; you can redistribute it and/or  *
 *   modify it under the terms of the GNU General Public License version 3 *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 *   The conexus library is distributed in the hope that it will be        *
 *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
 *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
 *   General Public License for more details.                              *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
#include <conexus.h>

#include <glibmm.h>

#include <iostream>

int main(int argc, char* argv[]) {

  // The data to send
  Glib::ustring data = "0123456789";
  Glib::ustring host = "127.0.0.1";
  int port1=1500, port2=1501, port3=1502;

  Glib::OptionContext option_context( "- IPv4 UDP POset Client" );
  Glib::OptionGroup option_group( "Options", "" );

  Glib::OptionEntry option_data;
  option_data.set_long_name( "data" );
  option_data.set_description( "Data to send [default=\"0123456789\"]" );
  option_group.add_entry( option_data, data );

  Glib::OptionEntry option_host;
  option_host.set_long_name( "tgt" );
  option_host.set_description( "Target host to send data to [default=127.0.0.1]" );
  option_group.add_entry( option_host, host );

  Glib::OptionEntry option_port1;
  option_port1.set_long_name( "port1" );
  option_port1.set_description( "UDP port1 to send data to [default=1500]" );
  option_group.add_entry( option_port1, port1 );

  Glib::OptionEntry option_port2;
  option_port2.set_long_name( "port2" );
  option_port2.set_description( "UDP port2 to send data to [default=1501]" );
  option_group.add_entry( option_port2, port2 );

  Glib::OptionEntry option_port3;
  option_port3.set_long_name( "port3" );
  option_port3.set_description( "UDP port3 to send data to [default=1502]" );
  option_group.add_entry( option_port3, port3 );

  option_context.set_main_group( option_group );

  option_context.parse( argc, argv );

  Conexus::init();

  // declare the local UDP connection point
  Conexus::IPv4::UDPPoset::pointer udpposet = Conexus::IPv4::UDPPoset::create();

  // Example of using the connect and send method. The send method doesn't
  // require an address, but instead requires a connected UDP object and
  // just sends to the connected destination.
  udpposet->add_destination(host, port1, 0);
  udpposet->add_destination(host, port2, 1);
  udpposet->add_destination(host, port3, -1);
  udpposet->write(data.c_str(), 11);

  return 0;
}

Generated on Wed Jul 8 15:50:07 2009 for conexus by doxygen 1.5.8