Script Sender example
The following example creates a ScriptSender
listening on port 12345
and sends the script
textmsg("Hello, World!")
when requested. A fully compilable example can be found in script_sender.cpp
33constexpr uint32_t PORT = 12345;
34
35int main(int argc, char* argv[])
36{
37 // Parse how may seconds to run
38 int second_to_run = -1;
39 if (argc > 2)
40 {
41 second_to_run = std::stoi(argv[2]);
42 }
43 urcl::control::ScriptSender sender(PORT, "textmsg(\"Hello, World!\")");
44
45 std::stringstream ss;
46 ss << "Waiting for incoming requests on port " << PORT;
47 if (second_to_run > 0)
48 {
49 ss << " for " << second_to_run << " seconds";
50 }
51 else
52 {
53 ss << " indefinitely";
54 }
55
56 std::cout << ss.str() << std::endl;
57
58 const auto start_time = std::chrono::system_clock::now();
59 while (second_to_run < 0 || std::chrono::system_clock::now() - start_time < std::chrono::seconds(second_to_run))
60 {
61 std::this_thread::sleep_for(std::chrono::milliseconds(500));
62 }
63 std::cout << "Timeout reached" << std::endl;
64
65 return 0;
66}