|
Packit |
bd2e5d |
(***********************************************************************)
|
|
Packit |
bd2e5d |
(* *)
|
|
Packit |
bd2e5d |
(* MLTk, Tcl/Tk interface of OCaml *)
|
|
Packit |
bd2e5d |
(* *)
|
|
Packit |
bd2e5d |
(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *)
|
|
Packit |
bd2e5d |
(* projet Cristal, INRIA Rocquencourt *)
|
|
Packit |
bd2e5d |
(* Jacques Garrigue, Kyoto University RIMS *)
|
|
Packit |
bd2e5d |
(* *)
|
|
Packit |
bd2e5d |
(* Copyright 2002 Institut National de Recherche en Informatique et *)
|
|
Packit |
bd2e5d |
(* en Automatique and Kyoto University. All rights reserved. *)
|
|
Packit |
bd2e5d |
(* This file is distributed under the terms of the GNU Library *)
|
|
Packit |
bd2e5d |
(* General Public License, with the special exception on linking *)
|
|
Packit |
bd2e5d |
(* described in file LICENSE found in the OCaml source tree. *)
|
|
Packit |
bd2e5d |
(* *)
|
|
Packit |
bd2e5d |
(***********************************************************************)
|
|
Packit |
bd2e5d |
open Camltk
|
|
Packit |
bd2e5d |
|
|
Packit |
bd2e5d |
let _ =
|
|
Packit |
bd2e5d |
let top_w = opentk () in
|
|
Packit |
bd2e5d |
let text0_w = Text.create top_w [] in
|
|
Packit |
bd2e5d |
let entry0_w = Entry.create top_w [] in
|
|
Packit |
bd2e5d |
let button0_w = Button.create top_w
|
|
Packit |
bd2e5d |
[Text "Quit"; Command (fun _ -> exit 0)] in
|
|
Packit |
bd2e5d |
let buffer = String.create 256 in
|
|
Packit |
bd2e5d |
let master_socket = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
|
|
Packit |
bd2e5d |
Unix.bind master_socket (Unix.ADDR_INET(Unix.inet_addr_any, 6789));
|
|
Packit |
bd2e5d |
Unix.listen master_socket 3;
|
|
Packit |
bd2e5d |
print_string "Please connect to port 6789..."; print_newline();
|
|
Packit |
bd2e5d |
let (sock, _) = Unix.accept master_socket in
|
|
Packit |
bd2e5d |
Fileevent.add_fileinput sock
|
|
Packit |
bd2e5d |
(fun _ ->
|
|
Packit |
bd2e5d |
let n = Unix.recv sock buffer 0 (String.length buffer) [] in
|
|
Packit |
bd2e5d |
let txt = String.sub buffer 0 n in
|
|
Packit |
bd2e5d |
Text.insert text0_w (TextIndex (End, [])) txt []);
|
|
Packit |
bd2e5d |
let send _ =
|
|
Packit |
bd2e5d |
let txt = Entry.get entry0_w ^ "\n" in
|
|
Packit |
bd2e5d |
Entry.delete_range entry0_w (At 0) End ;
|
|
Packit |
bd2e5d |
Unix.send sock txt 0 (String.length txt) [];
|
|
Packit |
bd2e5d |
() in
|
|
Packit |
bd2e5d |
bind entry0_w [([], KeyPressDetail "Return")] (BindSet ([], send));
|
|
Packit |
bd2e5d |
pack [text0_w; entry0_w; button0_w][Side Side_Top; Fill Fill_X; Expand true];
|
|
Packit |
bd2e5d |
mainLoop ()
|