Esempio n. 1
0
int main( int argc, char ** argv )
{
	std::string line;
	CEchoService * service = NULL;

	if ( argc != 3 )
	{
		printf("Usage: echoclient [host] [port] \n");
		return -1;
	}
	
	signal( SIGPIPE, SIG_IGN );
	signal( SIGINT, signal_handle );

	service = new CEchoService( 1, 200 ); 
	if ( service == NULL )
	{
		return -1;
	}

	service->start();

	if ( !service->connect( argv[1], atoi(argv[2]), 10 ) )
	{
		printf("service start failed \n");
		delete service;

		return -2;
	}

	g_Running = true;

	while ( g_Running ) 
	{
		int ch = getc(stdin);
		line.push_back( (char)ch );
		
		if ( ch == '\n' )
		{
			if ( strcmp( line.c_str(), "quit\n" ) == 0 )
			{
				g_Running = false;
				continue;
			}

			service->send2( line );
			line.clear();
		}
		fflush(stdin);
	}

	printf("EchoClient stoping ...\n");
	service->stop();

	delete service;

	return 0;

}