MeasureRequest.cpp 819 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // Created by zx on 2019/12/17.
  3. //
  4. #include "MeasureRequest.h"
  5. #include <nnxx/message.h>
  6. #include <nnxx/message_control.h>
  7. #include <nnxx/socket.h>
  8. #include <nnxx/reqrep.h>
  9. #include <nnxx/timeout.h>
  10. #include <nnxx/error.h>
  11. MeasureRequest::MeasureRequest(std::string connectStr)
  12. {
  13. m_connect_str=connectStr;
  14. }
  15. bool MeasureRequest::Request(std::string cmd,std::string& response)
  16. {
  17. nnxx::socket sock{ nnxx::SP, nnxx::REQ };
  18. sock.connect(m_connect_str);
  19. sock.send(cmd);
  20. nnxx::message message;
  21. try { nnxx::with_recv_timeout _ { sock, std::chrono::milliseconds(1000) };
  22. message=sock.recv();
  23. }
  24. catch (const nnxx::timeout_error &) {
  25. return false;
  26. }
  27. catch (const std::exception &) {
  28. return false;
  29. }
  30. response=nnxx::to_string(message);
  31. return true;
  32. }