diff --git a/src/mtconnect/source/adapter/agent_adapter/session_impl.hpp b/src/mtconnect/source/adapter/agent_adapter/session_impl.hpp index 41745fb7e..6f510118c 100644 --- a/src/mtconnect/source/adapter/agent_adapter/session_impl.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/session_impl.hpp @@ -83,6 +83,11 @@ namespace mtconnect::source::adapter::agent_adapter { LOG(error) << "Agent Adapter Target: " << m_request->getTarget(m_url); LOG(error) << "Agent Adapter " << what << ": " << ec.message() << "\n"; m_request.reset(); + + // Clear cached DNS resolution so hostname is re-resolved on reconnect. + // This handles DHCP environments where IP addresses may change. + m_resolution.reset(); + if (m_failed) m_failed(ec); } diff --git a/src/mtconnect/source/adapter/shdr/connector.cpp b/src/mtconnect/source/adapter/shdr/connector.cpp index fb7f5979d..9cd2602c5 100644 --- a/src/mtconnect/source/adapter/shdr/connector.cpp +++ b/src/mtconnect/source/adapter/shdr/connector.cpp @@ -149,7 +149,21 @@ namespace mtconnect::source::adapter::shdr { if (ec != boost::asio::error::operation_aborted) { LOG(info) << "reconnect: retrying connection"; - asio::dispatch(m_strand, boost::bind(&Connector::connect, this)); + // Re-resolve hostname to handle DHCP/dynamic IP environments. + // If the server is a hostname (not a static IP), re-resolve to get + // the current IP address in case it has changed. + boost::system::error_code parseEc; + asio::ip::address::from_string(m_server, parseEc); + if (parseEc) + { + // m_server is a hostname, re-resolve it + asio::dispatch(m_strand, boost::bind(&Connector::resolve, this)); + } + else + { + // m_server is a static IP address, just reconnect + asio::dispatch(m_strand, boost::bind(&Connector::connect, this)); + } } }); }