/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          client_test.cpp  -  description
                             -------------------
    begin                : Wed Apr 20, 2005
    copyright            : (C) 2005-2006 by Alexey Parshin
    email                : alexeyp@gmail.com
 ***************************************************************************/

/***************************************************************************
   This library is free software; you can redistribute it and/or modify it
   under the terms of the GNU Library General Public License as published by
   the Free Software Foundation; either version 2 of the License, or (at
   your option) any later version.

   This 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 Library
   General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

   Please report all bugs and problems to "alexeyp@gmail.com"
 ***************************************************************************/

#include <iostream>

#include <sptk3/CSocket.h>
#include <sptk3/CException.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifndef _WIN32
#include <fcntl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/time.h>
#endif

using namespace sptk;

int main (int argc, int argv[]) {
	try {
		CSocket client;
		client.port(3000);
		client.host("localhost");

		client.open();

		std::cout << "Connected\n";

		std::string data;

		client >> data;
		std::cout << "Receiving: " << data.c_str() << "\n";

		data = "Several copies of a single string";
		std::cout << "Sending: test data\n";
		client << data + "\n" + data + " " + data + "\n" + data + " " + data + " " + data + " " + data + "\n" + data + " " + data + "\n";

		std::cout << "Sending: end data\n";
		client << "EOD\n";

		client >> data;
		std::cout << "Receiving: " << data.c_str() << "\n";

		std::cout << "Sending: end session\n";
		client << "EOS\n";

		client >> data;
		std::cout << "Receiving: " << data.c_str() << "\n";
	}
	catch (std::exception& e) {
		std::cout << "Exception was caught:" << e.what() << "\nExiting.\n";
	}

	std::cout << "Exiting\n";

	return 0;
}
