mte/unikernel/duniverse/ocaml-tls/lwt/examples/echo_client_alpn.ml

23 lines
625 B
OCaml
Raw Normal View History

2025-11-11 02:07:51 +01:00
open Ex_common
open Lwt
let echo_client host port =
let open Lwt_io in
let port = int_of_string port in
let authenticator = null_auth in
Tls_lwt.Unix.connect
(get_ok Tls.Config.(client ~authenticator ~alpn_protocols:["http/1.1"; "h2"] ()))
(host, port) >>= fun t ->
match Tls_lwt.Unix.epoch t with
| Error () -> printl "Error"
| Ok epoch -> (
match epoch.Tls.Core.alpn_protocol with
| None -> printl "No protocol selected"
| Some protocol -> printl ("Selected protocol: " ^ protocol)
)
>>= fun () -> Tls_lwt.Unix.close t
let () =
Lwt_main.run (echo_client "127.0.0.1" "4433")