1.6.3. The Client

The client part is almost equal to the single threaded version. The only thing you have to do is to provide an additional parameter which contains a method that handles the response. This can be a normal function or a member of an object:


  TcpIpConnection conn (false, host, port);
  HttpProtocol prot(&conn);

  Requester client(&prot);
  MethodCall testcall ("testcall");
  client.call(testcall, "/RPC2", make_receiver(receiver_func));

The call() method sends the call and then creates a thread to start this method which is expected to handle the return value or maybe an error message. So the response handler should look something like this:


  void receiver_func (const MethodResponse &resp) 1
  {
    if (!resp.isOK())  2
    {
      ...
      return;
    }

    Mutex::Locker locker(receiver_mutex); 3
    unsigned num = Integer(resp.getResult()).getInteger(); 4
    ...
  }

1

Create a receiver for the response.

2

Handle a potential error response.

3

Lock this area againt concurrent access if neccessary.

4

Extract and process the response values.