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; }
int main() { CEchoService * service = NULL; signal( SIGPIPE, SIG_IGN ); signal( SIGINT, signal_handle ); service = new CEchoService( 4, 200000 ); if ( service == NULL ) { return -1; } service->start(); if ( !service->listen( "127.0.0.1", 9029 ) ) { printf("service start failed \n"); delete service; return -2; } g_Running = true; while ( g_Running ) { sleep(1); } printf("EchoServer stoping ...\n"); service->stop(); delete service; return 0; }