/* * Copyright (c) 1996 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include main(int argc, char *argv[]) { if(argc < 2) { cerr << "usage: client [r|n|rn]
" << endl; exit(1); } // determine if/what end of line character to append to message data const char *eol; if(argc>=3) { if(strcmp(argv[2],"r") == 0) eol = "\r"; else if(strcmp(argv[2],"n") == 0) eol = "\n"; else if(strcmp(argv[2],"rn") == 0) eol = "\r\n"; else eol = ""; } else eol = ""; // the communication stream socket SockIOStream io(argv[1]); io->connect(); Signal sigint(SIGINT); atSignal(sigint) { cerr << "interrupted" << endl; return 1; } while(cin) { // INPUT one message one line for input char req[1024]; cout << "> " << flush; cin.getline(req, 1024); if(! cin) return 1; strcat(req, eol); // SEND message io << req << endm << endt; if(!io) { cout << "message canceled" << endl; io.clear(); continue; } cout << "result: "<< flush; char *rep; io.gets(&rep, EOF) >> endm >> endt; if(!io) { cout << "message canceled" << endl; io.clear(); continue; } cout << rep << endl; } return 0; }