WebSocket client using civetweb

I was able to make a websocket client using civetweb.h and libRHTTP.so in windows subsystem for linux with ubuntu but the same could not be done using visual studio.

There is no C++ websocket client support in existing root library. I tried to make my own using civetweb library of TCivetweb class.

My code was

  1. gSystem->Load(“libRHTTP.dll”);
  2. .L civetweb.h
  3. .L ws_client.c
  4. run_websocket_client(“”, 1234, 0, “/ayan”, “Hello!”);

This worked fine with root in windows subsystem for linux ubuntu 18.

But with visual studio, it is not working in windows. Also in normal ubuntu unable to build with THttpServer support.

Error in Visula studio—>Error: Function mg_connect_websocket_client(host,port,secure,err_buf,sizeof(err_buf),path,NULL,websocket_client_data_handler,websocket_client_close_handler,pclient_data) is not defined in current scope

I checked the functions in libRHTTP.dll the function mg_connect_websocket_client is present in dll export table.
Please read tips for efficient and successful posting and posting code

ROOT Version: 6
Platform: Windows
Compiler: Visual Studio

Can anyone help me make a platform independent C++ websocket client program in ROOT.


Did you try tutorials/http/ws.C example.
It is basic example how websocket can be used with THttpServer.
I just tried on my Windows 10 machine - it is fine.


Thanks for the quick reply. The THttpServer works fine but I do not want to use that. I want to use a websocket client. I tried to implement one on my own using civetweb api and its ws_client.c example in github. That worked for my windows subsystem for linux ubuntu. But for Visual Studio build of ROOT the same process is not working. I have seen the libRHTTP.dll that has the function definitions required to run ws_client.c.


I never tried to use civetweb as websocket client. Maybe it shoud be compiled with special compiler options. The only you can do - try to ask civetweb developers for support.


Dear Linev,

I am sorry to bother you this much. But I think the problem is easily solvable as the functions I require are already present in libRHTTP.dll .

As the picture shows I have seen that the mg_connect_websocket_client function is already present in the libRHTTP.dll.

If you can tell me how to use this function directly from the dll or so file like load dll. If that support is present in cern ROOT.

You can find civetweb.h file in ROOT sources here:

Copy it to your location and include in your sources.
Probably then you can use it with libRHTTP.dll

Thanks linev for the prompt reply,

I already did that and exactly there lied the question which I asked. After i #include <civetweb.h> or I do root[0].L civetweb.h, I do not get the function mg_connect_websocket_client loaded in the cint interpreter. But as I had shown you earlier the function is present in the DLL. I am attaching the screenshot of my prompt. The function required is not present.

Probably, I know the problem.
civetweb does not provide dllimport / dllexport specifiers for its functions.
Therefore one cannot use it as is from DLL.
Most easy solution for you - take all civetweb sources and build executable yourself.
In this case dllimport is not required.

Dear Linev,

Thanks for the prompt reply. I may try and work like that. But I wanted to make a portable program in root that could communicate with our data acquisition server via websocket and display it using root libraries and is extensible by users. Thus i wanted to reduce external dependency and wanted to write the code using only root libraries.

The way you are suggesting is making civetweb an external library. Which has to be compiled for every platform. I did not want to do that. Then my code will become platform dependent.

If root civetweb library worked then i could have asked the users to only install root on their machine and run my code.

Probably, we should ask ROOT Windows expert - Bertrand @bellenot .

As I can see, WINDOWS_EXPORT_ALL_SYMBOLS specified in cmake files when building ROOT libraries. But I am not sure, if it is enough to be able use civetweb functions from libRHTTP.dll.

And in general - we use civetweb to implement HTTP server, but implementation can be changed at any time. Therefore civetweb.h not made public.

Yes, this is needed to properly export the symbols from the DLL

One can check (inspect) the exported symbols from the DLL with the dumpbin utility:

dumpbin /EXPORTS libRHTTP.dll

Sorry for the late reply.

libRHTTP.txt (72.9 KB)

I have run the command dumpbin /EXPORTS libRHTTP.dll . The output is upload here.

I see the civetweb function in the exports.

    960  3BF 00014BC0 G__set_cpp_environmentG__HTTP
    961  3C0 0002BA10 mg_check_feature
    962  3C1 0002BA20 mg_close_connection
    963  3C2 0002BAE0 mg_connect_client
    964  3C3 0002BDB0 mg_connect_client_secure
    965  3C4 0002BDD0 mg_connect_websocket_client
    966  3C5 0002BF50 mg_cry
    967  3C6 0002C0D0 mg_download
    968  3C7 0002C330 mg_get_builtin_mime_type
    969  3C8 0002C3F0 mg_get_context
    970  3C9 0002C410 mg_get_cookie
    971  3CA 0002C510 mg_get_header
    972  3CB 0002C530 mg_get_option
    973  3CC 0002C560 mg_get_ports
    974  3CD 000010E0 mg_get_request_info
    975  3CE 0002C5C0 mg_get_response
    976  3CF 0002C6B0 mg_get_response_code_text
    977  3D0 0002CBE0 mg_get_server_ports
    978  3D1 0002CCA0 mg_get_user_connection_data
    979  3D2 0002CCC0 mg_get_user_data
    980  3D3 0002CCE0 mg_get_valid_options
    981  3D4 0002CCF0 mg_get_var
    982  3D5 0002CD10 mg_get_var2
    983  3D6 0002CE70 mg_handle_form_request
    984  3D7 0002DE50 mg_lock_connection
    985  3D8 0002DE70 mg_lock_context
    986  3D9 0002DE90 mg_md5
    987  3DA 0002DF60 mg_modify_passwords_file
    988  3DB 0002E460 mg_printf
    989  3DC 0002E480 mg_read
    990  3DD 0002E870 mg_send_file
    991  3DE 0002E890 mg_send_mime_file
    992  3DF 0002E960 mg_set_auth_handler
    993  3E0 0002EC90 mg_set_request_handler
    994  3E1 0002EF20 mg_set_user_connection_data
    995  3E2 0002EF40 mg_set_websocket_handler
    996  3E3 0002F180 mg_start
    997  3E4 0002F780 mg_start_thread
    998  3E5 0002F950 mg_stop
    999  3E6 0002F9C0 mg_store_body
   1000  3E7 0002FB60 mg_strcasecmp
   1001  3E8 0002FCD0 mg_strncasecmp
   1002  3E9 0002FD30 mg_unlock_connection
   1003  3EA 0002FD50 mg_unlock_context
   1004  3EB 0002FD70 mg_url_decode
   1005  3EC 0002FEA0 mg_url_encode
   1006  3ED 0002FF50 mg_version
   1007  3EE 000300B0 mg_websocket_client_write
   1008  3EF 00030120 mg_websocket_write
   1009  3F0 00030220 mg_write

But they are not accessible by the root prompt. Please tell me a way to access these functions.

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