File: cli_test.cc

package info (click to toggle)
python-wslink 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,396 kB
  • sloc: python: 2,854; javascript: 1,176; cpp: 29; makefile: 3
file content (37 lines) | stat: -rw-r--r-- 785 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "../../../../cpp/wsWebsocketConnection.h"

#include <iostream>
#include <string>

const char* TOPIC  = "wslink.communication.channel";
const char* SECRET = "wslink-secret";
const char* HOST   = "127.0.0.1";
const char* PORT   = "8080";
const char* TARGET = "/ws";

using std::cout;
using std::endl;

int main(int argc, char *argv[])
{
  wsWebsocketConnection ws{SECRET};
  ws.connect(HOST, PORT, TARGET);

  ws.subscribe(TOPIC, 
      [](const json& json) -> void 
      {
        cout << json["id"] << " -> " << json["result"] << endl;
      });

  std::string line;
  while (std::cin >> line)
  {
    json args = { line.c_str() };
    ws.send("wslink.say.hello", nullptr, &args);
  }

  json result = {};
  ws.send("wslink.stop.talking", &result);

  return EXIT_SUCCESS;
}