-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathclient.ml
More file actions
21 lines (18 loc) · 793 Bytes
/
client.ml
File metadata and controls
21 lines (18 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
open Eio.Std
(* Prefix all trace output with "client: " *)
let traceln fmt = traceln ("client: " ^^ fmt)
module Read = Eio.Buf_read
module Write = Eio.Buf_write
(* Connect to [addr] on [net], send a message and then read the reply. *)
let run ~net ~addr =
Switch.run ~name:"client" @@ fun sw ->
traceln "Connecting to server at %a..." Eio.Net.Sockaddr.pp addr;
let flow = Eio.Net.connect ~sw net addr in
(* We use a buffered writer here so we can create the message in multiple
steps but still send it efficiently as a single packet: *)
Write.with_flow flow @@ fun to_server ->
Write.string to_server "Hello";
Write.char to_server ' ';
Write.string to_server "from client\n";
let reply = Read.(parse_exn take_all) flow ~max_size:100 in
traceln "Got reply %S" reply