/****************************************** * RandomQuotes_Iterative_UDP_TLI_Server.cpp * Auto-generated by Cliser, Fri Jul 28 15:07:18 EDT 2000 * except for the body of method: * RandomQuotes_Iterative_UDP_TLI_Server::run() * * See http://cs.calvin.edu/~cliser/ for more details. */ #include "UDP_Server_TLI_Communicator.h" #include "IterativeServer.h" #include class RandomQuotes_Iterative_UDP_TLI_Server : public IterativeServer { public: RandomQuotes_Iterative_UDP_TLI_Server(const unsigned short port); void interactWithClient(); private vector myQuotes; }; void RandomQuotes_Iterative_UDP_TLI_Server::interactWithClient() { int randomIndex = rand() % myQuotes.length(); string discard; this->receive(discard); this->send(myQuotes[randomIndex]); } RandomQuotes_Iterative_UDP_TLI_Server::RandomQuotes_Iterative_UDP_TLI_Server(const unsigned short port) : IterativeServer("RandomQuotes", port) { ifstream fin("quotes.txt"); string quote; for (;;) { getline(fin, quote); if ( fin.eof() ) break; myQuotes.push_back(quote); } fin.close(); } int main(int argc, char** argv) { unsigned short port = 9876; switch(argc) { default: cerr << "Usage: " << argv[0] << " []" << endl; return -1; case 2: port = (unsigned short)atoi(argv[1]); /* fall through */ case 1: RandomQuotes_Iterative_UDP_TLI_Server myServer(port); myServer.run(); } return 0; }