Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
cat.ml
delay.ml
dune
hello_world.ml
host.ml
http_get.ml
idle.ml
ifconfig.ml
mutex.ml
onchange.ml
pipe.ml
pipe_echo_server.ml
pipe_hello_world.ml
progress.ml
readme.ml
send_signal.ml
sigint.ml
spawn.ml
stdout.ml
tcp_echo_server.ml
tcp_hello_world.ml
thread_pool.ml
threads.ml
udp_echo_server.ml
udp_hello_world.ml

readme.ml

let () =
  Luv.DNS.getaddrinfo ~family:`INET ~node:"google.com" ~service:"80" ()
      begin fun result ->

    let address = (List.hd (Stdlib.Result.get_ok result)).addr in
    let socket = Luv.TCP.init () |> Stdlib.Result.get_ok in
    Luv.TCP.connect socket address begin fun _ ->

      Luv.Stream.write socket [Luv.Buffer.from_string "GET / HTTP/1.1\r\n\r\n"]
        (fun _ _ -> Luv.Stream.shutdown socket ignore);

      Luv.Stream.read_start socket (function
        | Error `EOF -> Luv.Handle.close socket ignore
        | Error _ -> exit 2
        | Ok response -> print_string (Luv.Buffer.to_string response))

    end
  end;

  Luv.Loop.run () |> ignore
You can’t perform that action at this time.