1
(***********************************************************************)
5
(* Pierre Weis, projet Cristal, INRIA Rocquencourt *)
7
(* Copyright 2001, 2004 Institut National de Recherche en Informatique *)
8
(* et en Automatique. All rights reserved. This file is distributed *)
9
(* under the terms of the Q Public License version 1.0. *)
11
(***********************************************************************)
15
(* A simple computation server: it receives messages from the GUI and
16
treat them accordingly.
18
In this example, there is a single acceptable message, namely
19
"button". When receiving this message, the server simply add one to the
20
number of such messages it has received so far. Then, the server's answer
21
to the GUI is just the new count. *)
23
let button_press_number = ref 0;;
25
let treat_button_press () =
26
incr button_press_number;
27
string_of_int !button_press_number;;
29
let parse_gui_message () =
30
let s = input_line stdin in
32
| "button" -> treat_button_press ()
33
| s -> "Syntax error: " ^ s;;
35
let treat_gui_message () =
36
let answer = parse_gui_message() in
37
output_string stdout answer;
38
output_char stdout '\n';
41
let computation_server () =
42
try while true do treat_gui_message () done
43
with End_of_file -> exit 0;;
45
computation_server ();;