/*************************************************************************** * 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> void data_to_file(const Conexus::Data d, Conexus::File::pointer f); int main(int argc, char* argv[]) { Conexus::init(); // declare the local TCP connection point Conexus::IPv4::TCP::pointer tcp = Conexus::IPv4::TCP::create(); // declare the address object that will be used to specify the destination Conexus::IPv4::Address addr; Conexus::File::pointer file = Conexus::File::create("test_received.txt", Conexus::FILE_WRITE|Conexus::FILE_CREATE); // Some default values for host and port char defaulthost[] = "127.0.0.1"; char* host = defaulthost; int port = 1505; // 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]); // Set the address object to the destination hostname and port addr.set_host(host); addr.set_port(port); tcp->signal_data().connect(sigc::bind(sigc::ptr_fun(&data_to_file),file)); tcp->connect(addr); tcp->start(); sleep(1); file->close(); tcp->close(); sleep(1); return 0; } void data_to_file(const Conexus::Data d, Conexus::File::pointer f) { std::cout << "Got data: " << (const char*)(d.data()) << std::endl; f->write( d ); }