diff --git a/commonLibs/livoxProto1/device.cpp b/commonLibs/livoxProto1/device.cpp index 2101993..b5014fb 100644 --- a/commonLibs/livoxProto1/device.cpp +++ b/commonLibs/livoxProto1/device.cpp @@ -205,6 +205,14 @@ bool Device::executeHandshake( boost::asio::ip::udp::socket socket(io_context); socket.open(boost::asio::ip::udp::v4()); + // Bind socket to cmdPort so we can receive the handshake response + boost::asio::ip::udp::endpoint localEndpoint( + boost::asio::ip::address_v4::any(), cmdPort); + socket.bind(localEndpoint); + + std::cout << __func__ << ": Bound socket to local port " << cmdPort + << " for handshake response" << std::endl; + // Get the IP addr of the SMO machine's iface that is facing the device. std::string smoIp = getSmoIp(deviceIP); @@ -425,6 +433,14 @@ void Device::startHeartbeat() componentThread->getIoService()); heartbeatSocket->open(boost::asio::ip::udp::v4()); + /** EXPLANATION: + * Bind heartbeat socket to cmdPort so heartbeats come from the same port + * as handshake. + */ + boost::asio::ip::udp::endpoint heartbeatLocalEndpoint( + boost::asio::ip::address_v4::any(), cmdPort); + heartbeatSocket->bind(heartbeatLocalEndpoint); + // Create heartbeat timer heartbeatTimer = std::make_unique( componentThread->getIoService()); @@ -454,7 +470,7 @@ void Device::sendHeartbeat() boost::asio::ip::udp::endpoint deviceEndpoint( boost::asio::ip::address::from_string(discoveredDevice.ipAddr), - cmdPort); + 65000); // Heartbeats and commands go to port 65000 heartbeatSocket->send_to( boost::asio::buffer(&heartbeatMsg, sizeof(heartbeatMsg)),