THttpServer Class: receive and sent request from multiple webpages from a unique port

Dear ROOT community!

I’d like to know how to correctly make use of Register and RegisterCommand functions of the THttpServer Class within a cmake compiled project.

I have two different web pages (A and B) and things work well when I lunch each of those pages separately in two different ports. However, when I open only one port (let’s say the on of A), and lunch a command from the web page B: it doesn’t work anymore! The command is sent but it not found (Error 404 in the page console), I suspect that something went wrong on how I use Register and RegisterCommand. Here is a simplified version of my code:

In my c++ code:

Web::Web(int port)
    : TNamed("Web", "Web") {

  m_http_server = new THttpServer(("http:" + std::to_string(port)).c_str());

  m_http_server->Register("/", this);

  std::string web_path = "path/to/my/page.html";

  m_http_server->SetDefaultPage(web_path.c_str());

  m_http_server->RegisterCommand("/CmdFolder/Do", "/Web/->Task(...)");

}

In my Html file:

document.getElementById("btn_start").onclick = function () {
        ...
cmd_str = `CmdFolder/Do/cmd.json?...`;
JSROOT.NewHttpRequest(cmd_str, "object").send();
};

As definition:

THttpServer *m_http_server;

Many thank you for any kind of help or guidance :pray:

Hi and welcome on the forum,

You only allowed to have one THttpServer instance for particular port number - let say 8080.
You cannot create second instance with the port number 8080. Neither in same ROOT application not in any other application which runs on the same host.

Regards,
Sergey

Hi and thank for prompt reply,

I also want to open one and unique port, that will support only one THttpServer. I am missing correct syntax on how to correctly register (both Register and RegisterCommand) a process that is executed from a webpage that opens at localhost:8080/NAME.html.

Best regards,
Abdelhamid.

Please check demos tutorials/http/httpcontrol.C and tutorials/http/httpaccess.C.

Here some info: HTTP Server

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