|
| 1 | +/// \file |
| 2 | +/// \ingroup tutorial_webgui |
| 3 | +/// This program demonstrates minimal server/client code for working with RWebWindow class |
| 4 | +/// File server.cxx shows how RWebWindow can be created and used |
| 5 | +/// In client.html simple client code is provided. |
| 6 | +/// |
| 7 | +/// \macro_code |
| 8 | +/// |
| 9 | +/// \author Sergey Linev |
| 10 | + |
| 11 | + |
| 12 | +#include <ROOT/RWebWindowsManager.hxx> |
| 13 | + |
| 14 | +std::shared_ptr<ROOT::Experimental::RWebWindow> window; |
| 15 | + |
| 16 | +int counter{0}; |
| 17 | + |
| 18 | +void ProcessData(unsigned connid, const std::string &arg) |
| 19 | +{ |
| 20 | + if (arg == "CONN_READY") { |
| 21 | + printf("connection established %u\n", connid); |
| 22 | + return; |
| 23 | + } |
| 24 | + |
| 25 | + if (arg == "CONN_CLOSED") { |
| 26 | + printf("connection closed\n"); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + printf("Get msg %s \n", arg.c_str()); |
| 31 | + |
| 32 | + counter++; |
| 33 | + |
| 34 | + if (arg == "get_text") { |
| 35 | + // send arbitrary text message |
| 36 | + window->Send(connid, Form("Message%d", counter)); |
| 37 | + } else if (arg == "get_binary") { |
| 38 | + // send float array as binary |
| 39 | + float arr[10]; |
| 40 | + for (int n = 0; n < 10; ++n) |
| 41 | + arr[n] = counter; |
| 42 | + window->SendBinary(connid, arr, sizeof(arr)); |
| 43 | + } else if (arg == "halt") { |
| 44 | + // terminate ROOT |
| 45 | + ROOT::Experimental::RWebWindowsManager::Instance()->Terminate(); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +void server() |
| 50 | +{ |
| 51 | + // create window, manager can handle many windows a time |
| 52 | + window = ROOT::Experimental::RWebWindowsManager::Instance()->CreateWindow(); |
| 53 | + |
| 54 | + // configure default html page |
| 55 | + // either HTML code can be specified or just name of file after 'file:' prefix |
| 56 | + window->SetDefaultPage("file:client.html"); |
| 57 | + |
| 58 | + // this is call-back, invoked when message received from client |
| 59 | + window->SetDataCallBack(ProcessData); |
| 60 | + |
| 61 | + window->SetGeometry(300, 500); // configure predefined geometry |
| 62 | + |
| 63 | + window->Show(); |
| 64 | +} |
0 commit comments