27 class TestHttpClientBackend :
public RemoteHandlerBackend
33 bool thread_should_run =
true;
36 const std::string address =
"0.0.0.0:8080";
38 const std::string ws_add =
"ws://" + address +
"/ws";
39 const std::string ht_add =
"http://" + address +
"";
42 TestHttpClientBackend()
46 if (rv = nng_bus0_open(&socket); rv != 0)
48 printf(
"pair open error\n");
51 if (rv = nng_dial(socket, ws_add.c_str(), &dialer, 0); rv != 0)
53 printf(
"server listen error\n");
57 rx_th = std::thread(&TestHttpClientBackend::rxThread,
this);
60 ~TestHttpClientBackend()
62 thread_should_run =
false;
69 while (thread_should_run)
73 nng_recv(socket, &ptr, &sz, NNG_FLAG_ALLOC | NNG_FLAG_NONBLOCK);
75 if (ptr != NULL && sz > 0)
77 uint8_t *dat = (uint8_t *)ptr;
78 std::string id((
char *)dat + 1, dat[0]);
79 uint8_t *payload = dat + 1 + (int)dat[0];
80 size_t psize = payload[0] << 24 | payload[1] << 16 | payload[2] << 8 | payload[3];
84 push_stream_data(
id, payload, psize);
91 nlohmann::ordered_json _get_cfg_list()
94 perform_http_request(ht_add +
"/list", res);
95 return nlohmann::ordered_json::parse(res);
98 nlohmann::ordered_json _get_cfg(std::string key)
101 perform_http_request_post(ht_add +
"/get", res, key);
102 return nlohmann::ordered_json::parse(res);
105 cfg_res_t _set_cfg(std::string key, nlohmann::ordered_json v)
110 perform_http_request_post(ht_add +
"/set", res, vs.dump());
111 return nlohmann::ordered_json::parse(res)[
"res"];