Interpretation of homework requirements, involving client/server communication
<p>I've been working on an assignment that asks us to implement some code provided to us that allows the creation of a server and client that can communicate.  I was to fork a process in main, and then test the various request options available, and then measure the difference in time it took to do this via the child process, or locally using a function.  I'm unsure if I've interpretated the requirements correctly though.  On top of this, all the timing functions return 0 seconds. Not sure if this is correct or not. I'll post a small portion of the code.</p>

<p>Homework statement (only a small portion):</p>

<blockquote>
  <p>Measure the invocation delay of a request (i.e. the time between the
  invocation of a request until the response comes back.) Compare that
  with the time to submit the same request string to a function that
  takes a request and returns a reply (as compared to a separate process
  that does the same). Submit a report that compares the two.</p>
</blockquote>

<p>The function declared before main:</p>

<pre><code>string myfunc(string request){
  //string myreq = request;
  RequestChannel my_func_channel("control", RequestChannel::CLIENT_SIDE);
  string reply1 = my_func_channel.send_request(request);
  return reply1;
}
</code></pre>

<p>And how I interpreted the directions in code:</p>

<pre><code>int main(int argc, char * argv[]) {

  //time variables
  time_t start, end;
  double time_req_1, time_req_func;

  cout &lt;&lt; "client.C  Starting...\n" &lt;&lt; flush;
  cout &lt;&lt; "Forking new process...\n " &lt;&lt; flush;      
  pid_t childpid = fork();

  if(childpid == -1)
    cout &lt;&lt; "Failed to fork.\n" &lt;&lt; flush;
  else if(childpid == 0){
    cout &lt;&lt; "***Loading Dataserver...\n" &lt;&lt; flush;
    //Load dataserver   
    RequestChannel my_channel("control", RequestChannel::CLIENT_SIDE);
    cout &lt;&lt; "***Dataserver Loaded.\n" &lt;&lt; flush;

    time(&amp;start);
    string reply1 = my_channel.send_request("hello");
    cout &lt;&lt; "***Reply to request 'hello' is '" &lt;&lt; reply1 &lt;&lt; "'\n" &lt;&lt; flush;
    time(&amp;end);
    time_req_1 = difftime(end,start);  

    cout &lt;&lt;"\n\nRequest 1 took     :  "&lt;&lt; time_req_1 &lt;&lt; flush;

  }
  else{//parent
    time(&amp;start);
    string s = myfunc("hello");
    time(&amp;end);
    time_req_func = difftime(end,start);
    cout &lt;&lt;"\nmyfunc Request took:  "&lt;&lt; time_req_func &lt;&lt; "\n" &lt;&lt; flush;

  }
  usleep(1000000);
}
</code></pre>

<p>This is an abbreviated version of my code, but contains everything you should need to figure out whats going on.  Have I done what the directions stated?  Also, is it likely that my 0 seconds results are correct?</p>
