conexus logo

ipv4_tcp_client.cpp

Conexus::IPv4::TCP Client Example

/***************************************************************************
 *   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 data1[] = "Hello";
  char data2[] = " World";
  char data3[] = "!!!";

  // Some default values for host and port
  char defaulthost[] = "127.0.0.1";
  char* host = defaulthost;
  int port = 1500;

  // 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) port = atoi(argv[2]);

  Conexus::init();

  // declare the local TCP connection point
  Conexus::IPv4::TCP::pointer tcp = Conexus::IPv4::TCP::create(host, port);

  tcp->write(data1, strlen(data1));
  std::cout << "\"" << data1 << "\" transmitted" << std::endl;
  sleep(1);
  
  Conexus::Data d = Conexus::Data(data2, strlen(data2));
  tcp << d;
  std::cout << "\"" << data2 << "\" transmitted" << std::endl;

  tcp << Conexus::Data(data3, strlen(data3));
  std::cout << "\"" << data3 << "\" transmitted" << std::endl;

  sleep(1);

  return 0;
}

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