1
(* A very simple slave:
2
- read the string " Ping" on stdin,
3
- then print the string "-pong" on stderr,
4
- and send it back on stdout
5
- until reading the string "stop" on stdin,
6
- then print the string "!\n" on stderr,
7
- send back the string "OK, bye!" on stdout,
10
Use the communication module Test_scanf2_io. *)
14
let ib = Scanf.Scanning.from_channel stdin;;
15
let ob = Buffer.create 1024
18
let send_string_pong ob = send_string ob oc "-pong";;
19
let send_string_okbye ob = send_string ob oc "OK, bye!";;
22
let s = receive_string ib in
24
| " Ping" -> Printf.eprintf "-pong"; flush stderr; send_string_pong ob
25
| "stop" -> Printf.eprintf "!\n"; flush stderr; send_string_okbye ob; exit 0
26
| s -> failwith ("Slave: unbound string " ^ s)