#include "socket.h"
#include "socket_stream.h"
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	cout << "Elmo Manager";

	try {
		tcp_client_socket	s(endpoint(argc==1 ? "localhost" : argv[1],4711));
		tcpstream			ts(s);

		cout << "CONNECTED " << s.my_endpoint() << " to " << s.peer() << endl;

		s.set_output_formatter(new line_output_formatter());

		ts << "Hello 1 from Elmo Manager" << endl;
		ts << "Hello 2 from Elmo Manager" << endl;
		ts << "Hello 3 from Elmo Manager" << endl;
		ts <<  endl;
		{
			string buf;

			while (s.recv(buf)>=0)
				cout << "Received: >" << buf << "<\n";
		}
	}
	catch (socket_error_ex& e) {
		cout << "Exception: " << e.what() << endl;
		cout << "Err=" << e.whaterr() << endl;
		cout << "Txt=" << e.whatsystext() << endl;
	}
	catch (socket_error& e) {
		cout << "Exception: " << e.what() << endl;
	}
}
