-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cohttp-eio(examples): update client and server example (#957)
Co-authored-by: Marcello Seri <[email protected]>
- Loading branch information
Showing
3 changed files
with
9 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
open Eio | ||
open Cohttp_eio | ||
|
||
let () = | ||
let host, port = ("www.example.org", 80) in | ||
Eio_main.run @@ fun env -> | ||
Switch.run @@ fun sw -> | ||
let hostname, port = ("www.example.org", 80) in | ||
let he = Unix.gethostbyname hostname in | ||
let addr = `Tcp (Eio_unix.Ipaddr.of_unix he.h_addr_list.(0), port) in | ||
let conn = Net.connect ~sw env#net addr in | ||
let host = (hostname, Some port) in | ||
let res = Client.get ~conn host "/" in | ||
print_string @@ Client.read_fixed res | ||
Eio.Net.with_tcp_connect ~host ~service:(string_of_int port) env#net | ||
(fun conn -> | ||
let host = (host, Some port) in | ||
let res = Client.get ~conn host "/" in | ||
print_string @@ Client.read_fixed res) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters