Last active
March 7, 2018 09:49
-
-
Save zzxx-husky/20abef6987fda2dbeaf58be6b359e233 to your computer and use it in GitHub Desktop.
An example to send an vector from one machine to another in CAF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include "caf/all.hpp" | |
//template<typename Inspect, typename T> | |
//typename Inspect::type_name inspect(Inspect &ins, std::vector<T> &vec) { | |
// return ins(caf::meta::type_name("vector"), vec); | |
//}; | |
#include "caf/io/all.hpp" | |
class Master : public caf::event_based_actor { | |
public: | |
explicit Master(caf::actor_config &cfg) : event_based_actor(cfg) {} | |
caf::behavior make_behavior() override { | |
return { | |
[=](std::string str) { | |
caf::aout(this) << str << std::endl; | |
this->send(caf::actor_cast<caf::actor>(this->current_sender()), std::vector<unsigned>()); | |
} | |
}; | |
} | |
}; | |
int main() { | |
caf::actor_system_config cfg; | |
cfg.load<caf::io::middleman>(); | |
caf::actor_system system(cfg); | |
caf::actor master = system.spawn<Master>(); | |
system.middleman().publish(master, 12345); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include "caf/all.hpp" | |
#include "caf/io/all.hpp" | |
class Worker : public caf::event_based_actor { | |
public: | |
Worker(caf::actor_config &cfg, const caf::actor &master) : event_based_actor(cfg) { | |
this->send(master, std::string("message from worker")); | |
} | |
caf::behavior make_behavior() override { | |
return { | |
[=](std::vector<unsigned> &a) { | |
caf::aout(this) << "vector from master" << std::endl; | |
} | |
}; | |
} | |
}; | |
int main() { | |
caf::actor_system_config cfg; | |
cfg.load<caf::io::middleman>(); | |
caf::actor_system system(cfg); | |
caf::actor master = system.middleman().remote_actor<caf::actor>("localhost", 12345).value(); | |
caf::actor worker = system.spawn<Worker>(master); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment