Listing 3: YAMI client.
// a simple YAMI client
#include "yami++.h"
using namespace YAMI;
#include <iostream>
#include <string>
using namespace std;
const string serverhost = "127.0.0.1";
const int serverport = 12340;
const int clientport = 12341;
// arbitrary name, used locally to distinguish between different domains
const string domainname = "someDomain";
// name of the logical remote object
const string objectname = "calculator";
int main()
{
try
{
netInitialize();
{
Agent agent(clientport);
// register the remote domain
agent.domainRegister(domainname, serverhost, serverport, 2);
string messagename = "multiply";
ParamSet paramset(2);
paramset.setInt(0, 5);
paramset.setInt(1, 6);
// send the message
auto_ptr<Message> message(
agent.send(domainname, objectname, messagename, paramset));
message->wait();
Message::eStatus status = message->getStatus();
if (status == Message::eReplied)
{
// read the response
auto_ptr<ParamSet> response(
message->getResponse());
int result = response->getInt(0);
cout << "the result is: " << result << endl;
}
else
{
cout << "the message was not replied correctly"
<< endl;
}
}
netCleanup();
}
catch (const exception &e)
{
cout << e.what() << endl;
}
}