diff options
Diffstat (limited to 'test/js/websockets_hello.ml')
-rw-r--r-- | test/js/websockets_hello.ml | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/js/websockets_hello.ml b/test/js/websockets_hello.ml new file mode 100644 index 0000000..41487b7 --- /dev/null +++ b/test/js/websockets_hello.ml @@ -0,0 +1,20 @@ +open Lwt.Syntax + +let () = + (* Echo is a websocket that... echoes you stuff. *) + let stream, push = Portal_ws.lwt_ws "wss://echo.websocket.org" in + push (Some "great text"); + push (Some "other text"); + push (Some "yet another text"); + push (Some "BYE"); + Lwt.async @@ + fun () -> + let+ s = Lwt_stream.iter + (fun greetings -> + match greetings with + (* When the websocket sends "BYE", we close. *) + | "BYE" -> print_endline "CLOSING BYE"; push None + | hello -> print_endline ("> " ^ hello)) + stream + in s + |