Skip to content

Commit 313e4b3

Browse files
committed
Create TCP Publisher with appropriate any address.
1 parent 785bf0c commit 313e4b3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

ecal/core/src/readwrite/tcp/ecal_writer_tcp.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@
3232
#include "ecal_utils/portable_endian.h"
3333

3434
#include <cstring>
35+
#include <asio.hpp>
36+
37+
namespace {
38+
constexpr int ANY_PORT = 0;
39+
40+
bool IsIpv6Supported()
41+
{
42+
asio::error_code ec;
43+
asio::ip::tcp::socket sock(asio::system_executor{});
44+
std::ignore = sock.open(asio::ip::tcp::v6(), ec);
45+
return !ec;
46+
}
47+
48+
std::string& GetPreferredAnyAddress() {
49+
static std::string any_address = IsIpv6Supported() ?
50+
"::" : "0.0.0.0";
51+
return any_address;
52+
}
53+
}
3554

3655
namespace eCAL
3756
{
@@ -50,7 +69,7 @@ namespace eCAL
5069
}
5170

5271
// create publisher
53-
m_publisher = std::make_shared<tcp_pubsub::Publisher>(g_tcp_writer_executor);
72+
m_publisher = std::make_shared<tcp_pubsub::Publisher>(g_tcp_writer_executor, GetPreferredAnyAddress(), ANY_PORT);
5473
m_port = m_publisher->getPort();
5574
}
5675

0 commit comments

Comments
 (0)