示例#1
0
void caf_main(actor_system& sys, const config& cfg) {
  auto& mm = sys.middleman();
  auto self =sys.spawn(math);
  if (cfg.server) {
    auto p = mm.publish(self, cfg.port);
    if (!p)
      cerr << "unable to publish actor: " << sys.render(p.error()) << "\n";
    else
      cout << "math actor published at port " << *p << "\n";
  } else {
    auto x = mm.remote_actor(cfg.host, cfg.port);
    if (!x)
      cerr << "unable to connect to server: " << sys.render(x.error()) << "\n";
    else {
	//self->send(*x,1);
      auto f = make_function_view(*x);
      cout << "f('add', 4, 2) = " << f(add_atom::value, 4, 2) << "\n"
           << "f('sub', 4, 2) = " << f(sub_atom::value, 4, 2) << "\n"
           << "f('mul', 4, 2) = " << f(mul_atom::value, 4, 2) << "\n"
           << "f('div', 4, 2) = " << f(div_atom::value, 4, 2) << "\n"
           << "f('div', 1, 0) = " << f(div_atom::value, 1, 0) << "\n";
    }
  }
}
示例#2
0
/// Tries to connect to given node.
/// @experimental
inline expected<node_id> connect(actor_system& sys, std::string host,
                                 uint16_t port) {
  return sys.middleman().connect(std::move(host), port);
}