1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // Created by zx on 2020/7/3.
- //
- #include <iostream>
- #include <nnxx/message>
- #include <nnxx/socket.h>
- #include <nnxx/bus.h>
- #include "measure_message.pb.h"
- #include <thread>
- int main()
- {
- nnxx::socket socket{ nnxx::SP, nnxx::BUS };
- socket.bind("tcp://127.0.0.1:9006");
- socket.connect("tcp://127.0.0.1:9005");
- int n=0;
- while(1)
- {
- std::string t_receive_string = socket.recv<std::string>(1);
- if(t_receive_string.length()>0) {
- message::Base_info base_msg;
- message::Measure_response_msg response;
- message::Measure_request_msg request;
- message::Error_manager error_code;
- request.ParseFromString(t_receive_string);
- base_msg.set_msg_type(message::eLocate_response_msg);
- base_msg.set_sender(message::eMeasurer);
- base_msg.set_receiver(message::eMain);
- response.set_command_id(request.command_id());
- response.set_terminal_id(4);
- response.mutable_base_info()->CopyFrom(base_msg);
- error_code.set_error_code(n++);
- response.mutable_error_manager()->CopyFrom(error_code);
- std::cout<<response.DebugString()<<std::endl;
- socket.send(response.SerializeAsString());
- std::cout<<" response length : "<<response.SerializeAsString().length()<<std::endl;
- }
- std::this_thread::yield();
- }
- }
|