~ubuntu-branches/ubuntu/hardy/ocaml-doc/hardy

« back to all changes in this revision

Viewing changes to examples/camltktutorial/servers/compute.ml

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2007-09-08 01:49:22 UTC
  • mfrom: (0.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070908014922-lvihyehz0ndq7suu
Tags: 3.10-1
* New upstream release.
* Removed camlp4 documentation since it is not up-to-date.
* Updated to standards version 3.7.2, no changes needed.
* Updated my email address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
(***********************************************************************)
2
 
(*                                                                     *)
3
 
(*                           Objective Caml                            *)
4
 
(*                                                                     *)
5
 
(*               Pierre Weis, projet Cristal, INRIA Rocquencourt       *)
6
 
(*                                                                     *)
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.                *)
10
 
(*                                                                     *)
11
 
(***********************************************************************)
12
 
 
13
 
(* $Id: Exp *)
14
 
 
15
 
(* A simple computation server: it receives messages from the GUI and
16
 
treat them accordingly.
17
 
 
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. *)
22
 
 
23
 
let button_press_number = ref 0;;
24
 
 
25
 
let treat_button_press () =
26
 
  incr button_press_number;
27
 
  string_of_int !button_press_number;;
28
 
 
29
 
let parse_gui_message () =
30
 
  let s = input_line stdin in
31
 
  match s with
32
 
  | "button" -> treat_button_press ()
33
 
  | s -> "Syntax error: " ^ s;;
34
 
 
35
 
let treat_gui_message () =
36
 
  let answer = parse_gui_message() in
37
 
  output_string stdout answer;
38
 
  output_char stdout '\n';
39
 
  flush stdout;;
40
 
 
41
 
let computation_server () =
42
 
  try while true do treat_gui_message () done
43
 
  with End_of_file -> exit 0;;
44
 
 
45
 
computation_server ();;