Locate_client.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // Created by zx on 2020/7/3.
  3. //
  4. #include <iostream>
  5. #include <nnxx/message>
  6. #include <nnxx/socket.h>
  7. #include <nnxx/bus.h>
  8. #include "measure_message.pb.h"
  9. #include <thread>
  10. int main()
  11. {
  12. nnxx::socket socket{ nnxx::SP, nnxx::BUS };
  13. socket.bind("tcp://127.0.0.1:9006");
  14. socket.connect("tcp://127.0.0.1:9005");
  15. int n=0;
  16. while(1)
  17. {
  18. std::string t_receive_string = socket.recv<std::string>(1);
  19. if(t_receive_string.length()>0) {
  20. message::Base_info base_msg;
  21. message::Measure_response_msg response;
  22. message::Measure_request_msg request;
  23. message::Error_manager error_code;
  24. request.ParseFromString(t_receive_string);
  25. base_msg.set_msg_type(message::eLocate_response_msg);
  26. base_msg.set_sender(message::eMeasurer);
  27. base_msg.set_receiver(message::eMain);
  28. response.set_command_id(request.command_id());
  29. response.set_terminal_id(4);
  30. response.mutable_base_info()->CopyFrom(base_msg);
  31. error_code.set_error_code(n++);
  32. response.mutable_error_manager()->CopyFrom(error_code);
  33. std::cout<<response.DebugString()<<std::endl;
  34. socket.send(response.SerializeAsString());
  35. std::cout<<" response length : "<<response.SerializeAsString().length()<<std::endl;
  36. }
  37. std::this_thread::yield();
  38. }
  39. }