livoxProto1: Fix source and dest port for handshake & heartbeat
Handshake: We must wait for the handshake ACK on the same port as the one we sent the handshake REQ from. Heartbeat: We must send the heartbeats from the same source port as the one we sent the handshake REQ from.
This commit is contained in:
@@ -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<boost::asio::deadline_timer>(
|
||||
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)),
|
||||
|
||||
Reference in New Issue
Block a user