I’m trying to build a web application using js_of_ocaml (incr_dom to be more precise), and I need to implement rpcs inside the web app. Specifically, I would want to send an Async_rpc_kernel.Rpc to a server given its host and port. However, since the unix part of Async is not supported with js_of_ocaml, I won’t have access to libraries such as Async_unix.Tcp, which prevents me from using the usual way of establishing a Rpc connection. (e.g. I would normally use Tcp.Where_to_connect.of_host_and_port combined with Rpc.Connection.client to establish a connection)
JavaScript doesn’t give you direct access to create TCP sockets, so you won’t be able to use anything like Async_unix. However, the Async_js library provides some of same RPC functionality using a WebSockets for the transport. See https://github.com/janestreet/async_js/blob/master/src/rpc.mli for the interface.
The server will also have to be configured to accept RPCs over WebSockets instead of (or in addition to) plain TCP.
Thanks for the reply! I looked over the Async_js rpc mli file, and it appears that most of the modules inside are straight from Async_rpc_kernel. The only difference is the Connection module, which it has a different implementation. Won’t that mean that the server can just support RPCs over plain TCP, and only the client needs to use the Connection module?
Has anyone tried using the Async_websocket module yet? I tried to install it from opam and it succeeded. But I’ve having difficulties compiling it in dune and utop.