ADD: added support for specify the address to listen to
This commit is contained in:
@@ -21,7 +21,7 @@ namespace WHISPER {
|
|||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InternalUDPListener(std::uint16_t port);
|
InternalUDPListener(std::uint16_t port, std::string address = "*");
|
||||||
~InternalUDPListener();
|
~InternalUDPListener();
|
||||||
void connect(std::shared_ptr<threadSafeQueue<WHISPER::Message>> receiver);
|
void connect(std::shared_ptr<threadSafeQueue<WHISPER::Message>> receiver);
|
||||||
void start();
|
void start();
|
||||||
@@ -36,6 +36,9 @@ namespace WHISPER {
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// @brief the address to listen to (default: "*")
|
||||||
|
std::string address_;
|
||||||
|
/// @brief the port to listen to
|
||||||
std::uint16_t port_;
|
std::uint16_t port_;
|
||||||
//zeromq io contex
|
//zeromq io contex
|
||||||
zmq::context_t ctx;
|
zmq::context_t ctx;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace WHISPER {
|
namespace WHISPER {
|
||||||
|
|
||||||
InternalUDPListener::InternalUDPListener(std::uint16_t port)
|
InternalUDPListener::InternalUDPListener(std::uint16_t port, std::string address):address_(address)
|
||||||
{
|
{
|
||||||
port_ = checkPort(port);
|
port_ = checkPort(port);
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ void InternalUDPListener::connect(std::shared_ptr<threadSafeQueue<WHISPER::Messa
|
|||||||
receiverSocket_ = std::make_shared<zmq::socket_t>(ctx,zmq::socket_type::dish);
|
receiverSocket_ = std::make_shared<zmq::socket_t>(ctx,zmq::socket_type::dish);
|
||||||
|
|
||||||
std::string portAsString = std::to_string(port_);
|
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
|
///used to set a custom time out to the socket
|
||||||
receiverSocket_->set(zmq::sockopt::rcvtimeo,100);
|
receiverSocket_->set(zmq::sockopt::rcvtimeo,100);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user