commore  1.0.6-SNAPSHOT
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
/examples/coding/Sender.cpp

Communication sender object To create a sender use the AutoRef factory and the create(const AString& spec) method. The first spec field (':' sparated) must contain the type name of implementation. Current avalaible implementation type in NtoolBox are: "SHM" for shared memory communication (restricted to interprocess) "TCPIP" for TCPIP communications "SHD" for shared directory communication The second field must contain the address of the connection SHM : the name of the shared memeory object TCPIP : the "<IP NUMBER OR HOST NAME>:<PORT NUMBER>"

Todo:
missing check_connection()
//
// Copyright (c) 2006-2014 Raphael David / CANTOR
//
#include "commore/Sender.h"
#include "commore/Error.h"
#include "commore/Tuple.h"
#include <stdio.h>
CMR_MODULE_DECLARE("EXAMPLE_SENDER");
using namespace std;
using namespace commore;
//
// This is an example of how to use the Sender class.
//
int main(int argc, const char* argv[])
{
int r= 0;
int count = 0;
init();
AString address = "TCPIP:localhost:6666";
ConsoleLogHook console_log_hook(true);
//GlobVarLog::set_default(10);
CMR_INFO("Start example Sender");
PSender sender;
sender.create(address);
Tuple p; sender->get_param(p);
CMR_INFO("Address:%0") << p.get_astring("address");
int c = getchar();
//
// Wait '.' is typed on the keyboard
//
while (c != '.')
{
if (c == 'a')
{
//
// Create a call
// And try send if to server
//
Tuple in_arg;
in_arg.set_int("count", count);
Tuple out_arg;
int rr = sender->call(in_arg, out_arg);
CMR_INFO("call count=%0 = %1") << out_arg.get_int("count") << rr;
count++;
}
c = getchar();
}
CMR_INFO("Stop example Sender");
return r;
}