Accepts an incoming connection and then receives like simple_recv
. You can connect directly to direct_recv
without a broker using simple_send.cpp. Make sure to stop the broker first or use a different port for direct_recv
.
#include "options.hpp"
#include <iostream>
#include <map>
private:
std::cout <<
"listening on " << l.
port() << std::endl;
}
};
std::string url;
listener_ready_handler listen_handler;
int expected;
int received;
public:
direct_recv(const std::string &s, int c) : url(s), expected(c), received(0) {}
listener = c.
listen(url, listen_handler);
}
if (proton::coerce<int>(msg.
id()) < received) {
return;
}
if (expected == 0 || received < expected) {
std::cout << msg.
body() << std::endl;
received++;
}
if (received == expected) {
}
}
};
int main(int argc, char **argv) {
std::string address("127.0.0.1:5672/examples");
int message_count = 100;
example::options opts(argc, argv);
opts.add_value(address, 'a', "address", "listen and receive on URL", "URL");
opts.add_value(message_count, 'm', "messages", "receive COUNT messages", "COUNT");
try {
opts.parse();
direct_recv recv(address, message_count);
return 0;
} catch (const example::bad_option& e) {
std::cout << opts << std::endl << e.what() << std::endl;
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 1;
}