Skip to content

Initialize sockets in ZMQPublisher and add host name argument. #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.82.0 (2025-04-23)

- Initialize sockets in ZMQPulisher and add host name argument.

## 0.81.1 (2025-04-14)

- Use only ZMQ for BinPickingTask when compiled with ZMQ.
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )
# Define here the needed parameters
# make sure to change the version in docs/Makefile
set (MUJINCLIENT_VERSION_MAJOR 0)
set (MUJINCLIENT_VERSION_MINOR 81)
set (MUJINCLIENT_VERSION_PATCH 1)
set (MUJINCLIENT_VERSION_MINOR 82)
set (MUJINCLIENT_VERSION_PATCH 0)
set (MUJINCLIENT_VERSION ${MUJINCLIENT_VERSION_MAJOR}.${MUJINCLIENT_VERSION_MINOR}.${MUJINCLIENT_VERSION_PATCH})
set (MUJINCLIENT_SOVERSION ${MUJINCLIENT_VERSION_MAJOR}.${MUJINCLIENT_VERSION_MINOR})
set (CLIENT_SOVERSION ${MUJINCLIENT_VERSION_MAJOR}.${MUJINCLIENT_VERSION_MINOR})
Expand Down
4 changes: 2 additions & 2 deletions include/mujincontrollerclient/mujinzmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MUJINCLIENT_API ZmqSubscriber
class MUJINCLIENT_API ZmqPublisher
{
public:
ZmqPublisher(const unsigned int port);
ZmqPublisher(const unsigned int port, const std::string& host = std::string());
virtual ~ZmqPublisher();

bool Publish(const std::string& messagestr);
Expand All @@ -62,7 +62,7 @@ class MUJINCLIENT_API ZmqPublisher
}

protected:
void _InitializeSocket(boost::shared_ptr<zmq::context_t> context);
void _InitializeSocket(boost::shared_ptr<zmq::context_t> context, const std::string& host);
void _DestroySocket();

boost::shared_ptr<zmq::context_t> _context;
Expand Down
7 changes: 4 additions & 3 deletions src/mujinzmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ void ZmqSubscriber::_DestroySocket()
}
}

ZmqPublisher::ZmqPublisher(const unsigned int port)
ZmqPublisher::ZmqPublisher(const unsigned int port, const std::string& host)
{
_port = port;
_InitializeSocket(nullptr, host);
}

ZmqPublisher::~ZmqPublisher()
Expand All @@ -192,7 +193,7 @@ bool ZmqPublisher::Publish(const std::string& messagestr)
return _socket->send(message);
}

void ZmqPublisher::_InitializeSocket(boost::shared_ptr<zmq::context_t> context)
void ZmqPublisher::_InitializeSocket(boost::shared_ptr<zmq::context_t> context, const std::string& host)
{
if (!!context) {
_context = context;
Expand All @@ -211,7 +212,7 @@ void ZmqPublisher::_InitializeSocket(boost::shared_ptr<zmq::context_t> context)
_socket->setsockopt(ZMQ_LINGER, 100); // ms
std::ostringstream port_stream;
port_stream << _port;
_socket->bind (("tcp://*:" + port_stream.str()).c_str());
_socket->bind (("tcp://" + (host.empty() ? "*" : host) + ":" + port_stream.str()).c_str());
}

void ZmqPublisher::_DestroySocket()
Expand Down