// // Created by zx on 2020/6/10. // #include "nnxx_client.h" Client::Client() { m_socket=nnxx::socket{ nnxx::SP, nnxx::REQ}; } Client::~Client() { std::lock_guard lck (m_lock); m_socket.close(); } Error_manager Client::connect(std::string connect_str) { std::lock_guard lck (m_lock); m_socket.connect(connect_str); return SUCCESS; } Error_manager Client::request(std::string request_str, std::string& response,unsigned int timeout) { std::lock_guard lck (m_lock); m_socket.send(request_str); nnxx::message message; try { nnxx::with_recv_timeout _ { m_socket, std::chrono::milliseconds(timeout) }; message=m_socket.recv(); } catch (const nnxx::timeout_error &) { // return Error_manager(NNXX_CLIENT_REQUEST_TIMEOUT,MINOR_ERROR,"nnxx client request timeout"); } catch (const std::exception &) { // return Error_manager(NNXX_CLIENT_REQUEST_UNKNOW,MINOR_ERROR,"nnxx client request unknow error"); } response=nnxx::to_string(message); return SUCCESS; }