#include "hmbdc/tips/tcpcast/Protocol.hpp"
#include "hmbdc/tips/Tips.hpp"
#include "hmbdc/os/Signals.hpp"
#include <iostream>
struct Hello
char msg[6] = "hello";
};
struct Receiver
:
Node<Receiver, std::tuple<Hello>> {
using SendMessageTuple = std::tuple<>;
void handleMessageCb(Hello const& m) {
cout << m.msg << endl;
}
};
int main(int argc, char** argv) {
if (argc < 2) {
cerr << argv[0] << " local-ip [recv]" << endl;
cerr << "start application as sender (default) or as Receiver" << endl;
return -1;
}
std::string ifaceAddr = argv[1];
bool isSender = argc <= 2;
if (!isSender) {
cout << "running as receiver, ctrl-c to exit" << endl;
}
config.
put(
"ifaceAddr", ifaceAddr);
if (isSender) {
config.
put(
"minRecvToStart", 1);
auto domain = MyDomain{config};
domain.addPub<std::tuple<Hello>>();
domain.publish(Hello{});
sleep(1);
domain.stop();
domain.join();
} else {
auto domain = MyDomain{config};
Receiver recv;
domain.start(recv);
domain.join();
}
}