conexus logo

ipv6_udpposet_client.cpp

This example client demonstrates sending to three destinations using Conexus::IPv6::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 <iostream>

int main(int argc, char* argv[]) {
  // The data to send
  char data[] = "0123456789";

  // Some default values for host and port
  char defaulthost[] = "::1";
  char* host = defaulthost;
  int port1 = 1500, port2=1501, port3=1502;

  // Check to see if user provided command line arguments and change
  // host and port variables if necessary
  if (argc > 1)
    host = argv[1];

  if (argc > 2)
    port1 = atoi(argv[2]);
  if (argc > 3)
    port2 = atoi(argv[3]);
  if (argc > 4)
    port3 = atoi(argv[4]);

  Conexus::init();

  // declare the local UDP connection point
  Conexus::IPv6::UDPPoset::pointer udp = Conexus::IPv6::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.
  udp->add_destination(host, port1, 0);
  udp->add_destination(host, port2, 1);
  udp->add_destination(host, port3, -1);
  udp->write(data, 11);

  return 0;
}

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