Help setting up Websocket_async client

Hello, I’m crossposting this post from /r/OCaml after seeing that this place is quite active, in hopes that someone can offer some assistance.

I’ve been trying to do this for longer than I care to admit. I’d like to use Websocket_async to connect to wss://echo.websocket.org and be able to read and write to it. My understanding is that I can use this function. For Uri.t I can pass Uri.of_string “wss://echo.websocket.org”, but I’m not sure where the Reader.t and Writer.t types are defined and what I’m expected to pass there.

The only example I could find was this, but it didn’t help me very much. I love the OCaml language, but every time I attempt to use external libraries it sadly is a struggle.

EDIT: A user on Reddit kindly pointed out that Reader and Writer are both part of Async_unix, but I’m still unsure how to proceed.

Take a look at https://github.com/vbmithr/ocaml-websocket/blob/master/async/wscat.ml for another example of how to use the library. The Reader.t and Writer.t you provide represent the underlying TCP connection to the remote server which needs to be created beforehand. In both examples, Conduit is being used to create that connection.

1 Like