Compile and run THttpServer

How can I compile and run a HTTP server using THttpServer class? If I try

#include <THttpServer.h>
#include <TGraph.h>

int main() {
    THttpServer *serv = new THttpServer("http:8080");
    TGraph* gr = new TGraph(10);
    gr->SetName("gr1");
    serv->Register("graphs/subfolder", gr);
}

the code compiles but the server immediately stops. Although in root interpreter it works fine.

Is there a tutorial on how to compile and run such a server using cmake/g++?

My ROOT prompt:

   ------------------------------------------------------------------
  | Welcome to ROOT 6.29/99                        (link to root)|
  | (c) 1995-2023, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Oct 10 2023, 20:54:14                 |
  | From tags/v6-30-00-rc1@v6-30-00-rc1                              |
  | With c++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0                   |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

Welcome to the ROOT Forum!
You need an instance of TApplication to process the events:

#include <TApplication.h>
#include <THttpServer.h>
#include <TGraph.h>

// cl -nologo -O2 -MD -GR -EHsc -Zc:__cplusplus -std:c++17 -I%ROOTSYS%\include httpserver.cxx /link -LIBPATH:%ROOTSYS%\lib libCore.lib libGui.lib libGpad.lib libHist.lib libTree.lib libGraf.lib libRoofit.lib libRoofitCore.lib libRHTTP.lib /out:httpserver.exe

int main(int argc, char* argv[])
{
   TApplication mainApp("mainApp", &argc, argv);
   THttpServer *serv = new THttpServer("http:8080");
   TGraph *gr = new TGraph(10);
   gr->SetName("gr1");
   serv->Register("graphs/subfolder", gr);
   mainApp.Run(kTRUE);
   return 0;
}
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.