1% BEGIN LICENSE BLOCK
2% Version: CMPL 1.1
3%
4% The contents of this file are subject to the Cisco-style Mozilla Public
5% License Version 1.1 (the "License"); you may not use this file except
6% in compliance with the License.  You may obtain a copy of the License
7% at www.eclipse-clp.org/license.
8%
9% Software distributed under the License is distributed on an "AS IS"
10% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11% the License for the specific language governing rights and limitations
12% under the License.
13%
14% The Original Code is  The ECLiPSe Constraint Logic Programming System.
15% The Initial Developer of the Original Code is  Cisco Systems, Inc.
16% Portions created by the Initial Developer are
17% Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
18%
19% Contributor(s):
20%
21% END LICENSE BLOCK
22
23:- module(joop_boot).
24
25:- export(jb_go/0).
26
27jb_go:-
28	% read the peer name atom specified on stdin.
29	read(Control),
30	set_password(Passwd),
31	remote_connect_setup(localhost/Port, Control, Socket),
32	% write the port and password out to stdout
33	% (java should read this)
34	write(Port),
35	write("\n"),
36	write(Passwd),
37	write("\n"),
38	flush(output),
39        % accept the connection
40        % blocks until connection is established, then
41	% waits for resume signal from remote side
42	remote_connect_accept(Control, Socket, block, _, Passwd, _),
43	% read a term from standard in
44        read(String),
45        % if the connection was successful on the java side, java writes
46        % "accept" into standard in, if unsuccessful, it writes "reject"
47	(String = accept -> % if accept was written,
48	session(Control);   % yield to the remote peer for a session
49      	% otherwise nothing
50	true).
51
52% yield to the remote peer until final resume is called, then disconnect.
53session(Control):-
54	remote_yield(Control),
55	remote_disconnect(Control).
56
57% set password to be random number
58set_password(Passwd):-
59	random(RN),
60	number_string(RN, Passwd).
61
62
63
64