100 lines
3 KiB
C++
Executable file
100 lines
3 KiB
C++
Executable file
/*
|
|
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 <cassert>
|
|
#include <cstring>
|
|
#include <iostream>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
|
|
#include "reqchannel.h"
|
|
#include "semaphore.h"
|
|
|
|
using namespace std;
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
/* DATA STRUCTURES */
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
/* -- (none) -- */
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
/* CONSTANTS */
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
/* -- (none) -- */
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
/* FORWARDS */
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
/* -- (none) -- */
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
/* MAIN FUNCTION */
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
int main(int argc, char * argv[]) {
|
|
|
|
|
|
|
|
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);
|
|
}
|