let sender _ r w =
let stdin = Lazy.force Reader.stdin in
let rec loop r w =
printf "> ";
(* Step one: read a line from the user. *)
Reader.read_line stdin >>= function
| `Eof -> (printf "Error reading stdin\n"; return ())
| `Ok line -> begin
(* Step two: send it to the server. *)
Writer.write_line w line;
(* Step three: read back the echoed string. *)
Reader.read_line r >>= function
(* Step four: print it out. *)
| `Eof -> (printf "Error reading server\n"; return ())
| `Ok line -> (print_endline line; loop r w)
end
in
loop r w