I’m having some trouble getting the ws.C example web socket code (from the root tutorials dir) working. I haven’t made any major changes to the ws.C or ws.htm files apart from replacing
var path = window.location.href;
path = path.replace("http://", "ws://") + "root.websocket";
with
var path = "ws://localhost:8080/root.websocket";
The error I get when I try to open the client is :
WebSocket connection to 'ws://localhost:8080/root.websocket' failed: Connection closed before receiving a handshake response
I’m using ROOT v6.14 and the browser I’m using is chromium.
Thank you for the quick reply @linev! The original ws.C and ws.htm files give me the error:
Uncaught DOMException: Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. 'file' is not allowed.
at file:///home/pi/Downloads/root-6.14.06/builddir/macros/ws.htm:27:20
If I edit the ws.htm file like I described in my first message and leave the ws.C file untouched I still get the error:
WebSocket connection to 'ws://localhost:8090/root.websocket' failed: Connection closed before receiving a handshake response
In my edited files I did change the port numbers so the matched in both files.
Also in case this could be the root of the problem, I’m trying to get this working on a Raspberry Pi.
I guess, it is very important notice.
Means you start browser on other computer?
In that case you should comment out last lines in ws.C where macro tries to strat browser with xdg-open command. And just type in your browser URL like: http://raspberry_name_or_ip:8090/folder1/name1/
I’m running raspbian desktop on the Raspberry Pi, so the browser starts on the same computer (the RasPi). I have already commented those lines out on the edited file anyways, but I still get the same error.
In principle, it works for me on my Linux machine.
Have no idea would could be wrong on Raspberry Pi.
Try to bind http server directly to loopback address:
THttpServer *serv = new THttpServer("http:8080?loopback");