Skip to content
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

[core] Added support for mdns (hostname.local) for TCP connections #2048

Merged
merged 1 commit into from
Feb 27, 2025
Merged
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
2 changes: 1 addition & 1 deletion ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (ECAL_CORE_COMMAND_LINE)
endif()

if (ECAL_CORE_TRANSPORT_TCP)
find_package(tcp_pubsub REQUIRED)
find_package(tcp_pubsub 2 REQUIRED)
endif()

# If we're currently doing a build within a git repository, we will configure the header files.
Expand Down
15 changes: 11 additions & 4 deletions ecal/core/src/readwrite/tcp/ecal_reader_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ namespace eCAL
auto sessions = m_subscriber->getSessions();
for (const auto& session : sessions)
{
auto address = session->getAddress();
auto port = session->getPort();
if ((address == host_name_) && (port == port_))
// Get list of possible publishers of this session. We assume, that the
// first element holds the hostname, while the second elements holds
// hostname.local
auto publisher_list = session->getPublisherList();
if ((publisher_list.front().first == host_name_) && (publisher_list.front().second == port_))
{
new_session = false;
break;
Expand All @@ -79,7 +81,12 @@ namespace eCAL
// add new session and activate callback if we add the first session
if (new_session)
{
m_subscriber->addSession(host_name_, port_, m_attributes.max_reconnection_attempts);
// Add possible hostnames:
// 1. hostname:port
// 2. hostname.local:port (-> i.e. the mDNS variant)
const std::vector<std::pair<std::string, uint16_t>> publishers = { { host_name_, port_ } , {host_name_ + ".local", port_} };

m_subscriber->addSession(publishers, m_attributes.max_reconnection_attempts);
if (!m_callback_active)
{
m_subscriber->setCallback(std::bind(&CDataReaderTCP::OnTcpMessage, this, std::placeholders::_1));
Expand Down
8 changes: 5 additions & 3 deletions thirdparty/tcp_pubsub/build-tcp_pubsub.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
include_guard(GLOBAL)

# Build as static library
set(TCP_PUBSUB_LIBRARY_TYPE STATIC)
set(TCP_PUBSUB_USE_BUILTIN_ASIO OFF)
set(TCP_PUBSUB_BUILD_SAMPLES OFF)
set(TCP_PUBSUB_BUILD_ECAL_SAMPLES OFF)
set(TCP_PUBSUB_USE_BUILTIN_ASIO OFF)
set(TCP_PUBSUB_USE_BUILTIN_RECYCLE OFF)
set(TCP_PUBSUB_BUILD_TESTS OFF)
set(TCP_PUBSUB_BUILD_TESTS OFF)
set(TCP_PUBSUB_LIBRARY_TYPE STATIC)

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tcp_pubsub/tcp_pubsub thirdparty/tcp_pubsub EXCLUDE_FROM_ALL SYSTEM)

Expand Down
Loading