From 290f7a9540382af50f587da7c65bd73a72cbfb05 Mon Sep 17 00:00:00 2001 From: hwinkel Date: Tue, 26 Sep 2023 10:55:21 +0200 Subject: [PATCH] ADD: added support for specify the address to listen to --- include/WHISPER/InternalUDPListener.hpp | 5 ++++- src/WHISPER/InternalUDPListener.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/WHISPER/InternalUDPListener.hpp b/include/WHISPER/InternalUDPListener.hpp index d5f1a00..cc9004d 100644 --- a/include/WHISPER/InternalUDPListener.hpp +++ b/include/WHISPER/InternalUDPListener.hpp @@ -21,7 +21,7 @@ namespace WHISPER { public: - InternalUDPListener(std::uint16_t port); + InternalUDPListener(std::uint16_t port, std::string address = "*"); ~InternalUDPListener(); void connect(std::shared_ptr> receiver); void start(); @@ -36,6 +36,9 @@ 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; diff --git a/src/WHISPER/InternalUDPListener.cpp b/src/WHISPER/InternalUDPListener.cpp index 08250b4..ed3d197 100644 --- a/src/WHISPER/InternalUDPListener.cpp +++ b/src/WHISPER/InternalUDPListener.cpp @@ -9,7 +9,7 @@ namespace WHISPER { -InternalUDPListener::InternalUDPListener(std::uint16_t port) +InternalUDPListener::InternalUDPListener(std::uint16_t port, std::string address):address_(address) { port_ = checkPort(port); } @@ -37,7 +37,7 @@ void InternalUDPListener::connect(std::shared_ptr(ctx,zmq::socket_type::dish); std::string portAsString = std::to_string(port_); - receiverSocket_->bind("udp://*:"+portAsString); + receiverSocket_->bind("udp://"+address_+":"+portAsString); ///used to set a custom time out to the socket receiverSocket_->set(zmq::sockopt::rcvtimeo,100); }