/* File: simpleclient.C Author: R. Bettati Department of Computer Science Texas A&M University Date : 2013/01/31 Simple client main program for MP3 in CSCE 313 */ /*--------------------------------------------------------------------------*/ /* DEFINES */ /*--------------------------------------------------------------------------*/ /* -- (none) -- */ /*--------------------------------------------------------------------------*/ /* INCLUDES */ /*--------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include "reqchannel.h" #include "semaphore.h" using namespace std; /*--------------------------------------------------------------------------*/ /* DATA STRUCTURES */ /*--------------------------------------------------------------------------*/ /* -- (none) -- */ /*--------------------------------------------------------------------------*/ /* CONSTANTS */ /*--------------------------------------------------------------------------*/ /* -- (none) -- */ /*--------------------------------------------------------------------------*/ /* FORWARDS */ /*--------------------------------------------------------------------------*/ /* -- (none) -- */ /*--------------------------------------------------------------------------*/ /* MAIN FUNCTION */ /*--------------------------------------------------------------------------*/ int main(int argc, char * argv[]) { unsigned int n = 20, b = 100, w = 5; int option = -1; while ((option = getopt(argc, argv, "n:b:w:")) != -1){ switch (option){ case 'n' : n = atoi(optarg); break; case 'b' : b = atoi(optarg); break; case 'w' : w = atoi(optarg); break; } } cout << n << b << w << endl; Semaphore sema(5); cout << "CLIENT STARTED:" << endl; pid_t pid = fork(); if(pid == 0){ cout << "Establishing control channel... " << flush; RequestChannel chan("control", RequestChannel::CLIENT_SIDE); cout << "done." << endl; /* -- Start sending a sequence of requests */ string reply1 = chan.send_request("hello"); cout << "Reply to request 'hello' is '" << reply1 << "'" << endl; string reply2 = chan.send_request("data Joe Smith"); cout << "Reply to request 'data Joe Smith' is '" << reply2 << "'" << endl; string reply3 = chan.send_request("data Jane Smith"); cout << "Reply to request 'data Jane Smith' is '" << reply3 << "'" << endl; string reply5 = chan.send_request("newthread"); cout << "Reply to request 'newthread' is " << reply5 << "'" << endl; RequestChannel chan2(reply5, RequestChannel::CLIENT_SIDE); string reply6 = chan2.send_request("data John Doe"); cout << "Reply to request 'data John Doe' is '" << reply6 << "'" << endl; string reply7 = chan2.send_request("quit"); cout << "Reply to request 'quit' is '" << reply7 << "'" << endl; string reply4 = chan.send_request("quit"); cout << "Reply to request 'quit' is '" << reply4 << "'" << endl; }else{ execve("dataserver", argv, argv); } usleep(1000000); } /* void* Worker_Thread(); void* Req_Thread(); void* */