ADD: added new constructor
This commit is contained in:
@@ -21,14 +21,14 @@ namespace WHISPER {
|
||||
|
||||
|
||||
public:
|
||||
InternalUDPListener(std::uint16_t port, std::string address = "*");
|
||||
InternalUDPListener(std::uint16_t port);
|
||||
InternalUDPListener(std::string address, std::uint16_t port);
|
||||
|
||||
~InternalUDPListener();
|
||||
[[DEPRECATED]]
|
||||
[[deprecated]]
|
||||
void connect(std::shared_ptr<threadSafeQueue<WHISPER::Message>> receiver);
|
||||
void connect();
|
||||
|
||||
void addReceiverQueue(std::shared_ptr<threadSafeQueue<WHISPER::Message>> receiver);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
@@ -41,9 +41,7 @@ namespace WHISPER {
|
||||
|
||||
|
||||
private:
|
||||
/// @brief the address to listen to (default: "*")
|
||||
std::string address_;
|
||||
/// @brief the port to listen to
|
||||
std::uint16_t port_;
|
||||
//zeromq io contex
|
||||
zmq::context_t ctx;
|
||||
|
||||
@@ -9,10 +9,15 @@
|
||||
|
||||
namespace WHISPER {
|
||||
|
||||
InternalUDPListener::InternalUDPListener(std::uint16_t port, std::string address):address_(address)
|
||||
InternalUDPListener::InternalUDPListener(std::uint16_t port):address_("*")
|
||||
{
|
||||
port_ = checkPort(port);
|
||||
}
|
||||
InternalUDPListener::InternalUDPListener(std::string address, std::uint16_t port):address_(address)
|
||||
{
|
||||
port_ = checkPort(port);
|
||||
}
|
||||
|
||||
|
||||
InternalUDPListener::~InternalUDPListener()
|
||||
{
|
||||
@@ -29,7 +34,7 @@ InternalUDPListener::~InternalUDPListener()
|
||||
|
||||
void InternalUDPListener::connect(std::shared_ptr<threadSafeQueue<WHISPER::Message>> receiver)
|
||||
{
|
||||
receiverQueue_ = receiver;
|
||||
receiverQueue_ = receiver;
|
||||
|
||||
if (receiverSocket_ == nullptr)
|
||||
{
|
||||
@@ -55,7 +60,7 @@ void InternalUDPListener::connect()
|
||||
receiverSocket_ = std::make_shared<zmq::socket_t>(ctx,zmq::socket_type::dish);
|
||||
|
||||
std::string portAsString = std::to_string(port_);
|
||||
receiverSocket_->bind("udp://"+address_+":"+portAsString);
|
||||
receiverSocket_->bind("udp://*:"+portAsString);
|
||||
///used to set a custom time out to the socket
|
||||
receiverSocket_->set(zmq::sockopt::rcvtimeo,100);
|
||||
}
|
||||
@@ -123,7 +128,14 @@ void InternalUDPListener::stop()
|
||||
void InternalUDPListener::subscribe(WHISPER::MsgTopics topic)
|
||||
{
|
||||
subscribedTopics.push_back(topic);
|
||||
receiverSocket_->join(WHISPER::MsgTopicsMap[topic].c_str());
|
||||
LOG_S(WARNING)<< WHISPER::MsgTopicsMap[topic].c_str();
|
||||
try {
|
||||
|
||||
receiverSocket_->join(WHISPER::MsgTopicsMap[topic].c_str());
|
||||
} catch (const std::exception& e)
|
||||
{
|
||||
LOG_S(ERROR)<<e.what();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user