Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
server.cxx
Go to the documentation of this file.
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#include <ROOT/RWebWindow.hxx>
12
13std::shared_ptr<ROOT::Experimental::RWebWindow> window;
14
15int counter{0};
16
17void ProcessData(unsigned connid, const std::string &arg)
18{
19 printf("Get msg %s \n", arg.c_str());
20
21 counter++;
22
23 if (arg == "get_text") {
24 // send arbitrary text message
25 window->Send(connid, Form("Message%d", counter));
26 } else if (arg == "get_binary") {
27 // send float array as binary
28 float arr[10];
29 for (int n = 0; n < 10; ++n)
30 arr[n] = counter;
31 window->SendBinary(connid, arr, sizeof(arr));
32 } else if (arg == "halt") {
33 // terminate ROOT
34 window->TerminateROOT();
35 }
36}
37
38void server()
39{
40 // create window
42
43 // configure default html page
44 // either HTML code can be specified or just name of file after 'file:' prefix
45 window->SetDefaultPage("file:client.html");
46
47 // this is call-back, invoked when message received from client
48 window->SetDataCallBack(ProcessData);
49
50 window->SetGeometry(300, 500); // configure predefined geometry
51
52 window->Show();
53}
char * Form(const char *fmt,...)
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
const Int_t n
Definition legend1.C:16