Js_of_ocaml missing primitives

I’m trying to use js_of_ocaml for GUI and Unix sockets for server-client interactions, however, when compiling, i got the following warning:

There are some missing primitives
Dummy implementations (raising ‘Failure’ exception) will be used if they are not available at runtime.
You can prevent the generation of dummy implementations with the commandline option ‘–disable genprim’
Missing primitives:

is there any way to solve this issue? I know one solution is to switch to cohttp, but that way we have to rewrite all the server code. Thanks.

It is not possible for JavaScript programs to open arbitrary sockets, for good security reasons. Imagine, for example, if someone at your company inside the firewall could unknowingly run a program if they simply browsed some web site that started port scanning your entire network or worse.

It is similarly not possible for JavaScript in the browser to open files on the local file system, launch processes, etc. If it was, pretty terrible security problems would occur.

Since js_of_ocaml running in the browser is running on top of JavaScript, it is only able to do what JavaScript is allowed to do.

Thanks Perry. I see. If I want to keep the server part written in Unix sockets, will this webSocket of js_of_ocaml do the trick?

Websockets aren’t normal TCP connections, which are what the BSD Sockets API is for. They’re their own protocol that runs over Port 80 or 443. After establishing a normal http or https connection, a client “upgrades” their connection to a web socket and then multiplexes that connection. You thus cannot communicate with a client that uses websockets over normal TCP ports etc.

If you really want to use websockets, I suggest learning a bit about the technology first, and then consider how to use them with a js_of_ocaml client.