# Help debug ocaml async websocket echo client

**URL:** <https://discuss.ocaml.org/t/help-debug-ocaml-async-websocket-echo-client/17782>\
**Category:** Learning\
**Tags:** websocket, async\
**Created:** [February 6, 2026, 11:58pm UTC](https://discuss.ocaml.org/t/help-debug-ocaml-async-websocket-echo-client/17782 "2026-02-06T23:58:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivanov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vivanov/32/4455_2.png) [@vivanov](https://discuss.ocaml.org/u/vivanov)\
**Post date:** [February 6, 2026, 11:58pm UTC](https://discuss.ocaml.org/t/help-debug-ocaml-async-websocket-echo-client/17782/1 "2026-02-06T23:58:52Z")

</div>

Hey, I am connecting a client to the web sockets org echo server. This is my code

```auto
open Core
open Async

let send_and_receive () =
  let uri = Uri.of_string "wss://echo.websocket.org" in

  print_endline "connecting";
  let%bind _response, websocket =
    Cohttp_async_websocket.Client.create uri >>| Or_error.ok_exn
  in
  let reader, writer = Websocket.pipes websocket in

  print_endline "writing";
  let%bind () = Pipe.write writer "lol omg wut" in

  print_endline "reading";
  let%bind () =
    match%bind Pipe.read reader with
    | `Eof ->
        print_endline "Eof";
        return ()
    | `Ok s ->
        print_endline "Ok";
        let prefix = Time_ns_unix.now () |> Time_ns_unix.to_string in
        let s = prefix ^ " " ^ s in
        print_endline s;
        return ()
  in
  return ()

let () =
  Command.async ~summary:"Websocket client sample"
    (Command.Param.return send_and_receive)
  |> Command_unix.run

```

This is the error I am getting

```auto
connecting
(monitor.ml.Error
 ("attempt to use closed writer"
  ((file_descr 8) (info (writer app_to_ssl)) (kind Fifo)))
 ("Called from Base__Error.raise_s in file \"src/error.ml\", line 10, characters 26-47"
  "Called from Async_unix__Writer0.Checked_writes.write in file \"src/writer0.ml\" (inlined), line 1648, characters 4-22"
  "Called from Cohttp_async__Io.write.(fun) in file \"cohttp-async/src/io.ml\", line 96, characters 6-25"
  "Called from Cohttp__Request.Make.write_header in file \"cohttp/src/request.ml\", line 224, characters 4-24"
  "Called from Cohttp_async_websocket.Client.create.(fun) in file \"src/cohttp_async_websocket.ml\", line 607, characters 23-59"))

```

Can you please help me debug this one?

---

<div class="post-metadata">

**Author:** ![jrfondren](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jrfondren/32/3871_2.png) [@jrfondren](https://discuss.ocaml.org/u/jrfondren)\
**Post date:** [February 7, 2026, 3:06am UTC](https://discuss.ocaml.org/t/help-debug-ocaml-async-websocket-echo-client/17782/2 "2026-02-07T03:06:45Z")

</div>

Your code succeeds for me with this addition to the `Client.create`call:

```ocaml
~force_ssl_overriding_SNI_hostname:"echo.websocket.org"

```

ouput:

```auto
connecting                          
writing
reading
Ok
2026-02-06 21:00:20.956986126-06:00 Request served by ...

```

But my guess is that this endpoint is relatively strict and that the library’s subtly wrong - something like trying to write without first reading.

---

<div class="post-metadata">

**Author:** ![vivanov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vivanov/32/4455_2.png) [@vivanov](https://discuss.ocaml.org/u/vivanov)\
**Post date:** [February 7, 2026, 3:52am UTC](https://discuss.ocaml.org/t/help-debug-ocaml-async-websocket-echo-client/17782/3 "2026-02-07T03:52:08Z")

</div>

Thank you, Julian, this works 🙂 #resolved
