diff --git a/src/DirectCommunicationClient.cpp b/src/DirectCommunicationClient.cpp index 1891ec6..851a8c0 100644 --- a/src/DirectCommunicationClient.cpp +++ b/src/DirectCommunicationClient.cpp @@ -1,6 +1,7 @@ #include - +#include +#include #include "zmq.hpp" #include #include @@ -82,13 +83,38 @@ namespace DirectCommunication std::string DirectCommunicationClient::getLatestMessage() { + + if (receivedMessages_.size() > 0) { std::string msg; receivedMessages_.get(msg); return msg; + }else{ + auto start = std::chrono::steady_clock::now(); + while (receivedMessages_.size() == 0) + { + auto now = std::chrono::steady_clock::now(); + auto elapsed = duration_cast(now - start); + + + if (elapsed >= std::chrono::milliseconds(5000)) { // replace 5000 with the number of milliseconds you want to wait + + return "NULL"; + break; + + } + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + std::string msg; + receivedMessages_.get(msg); + return msg; + + } return "NULL"; + + } void DirectCommunicationClient::workerFunc_()