From jan@swi.psy.uva.nl Thu Sep 27 09:30:46 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f8R7Ujv26009;
	Thu, 27 Sep 2001 09:30:45 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f8R7UjE25742;
	Thu, 27 Sep 2001 09:30:45 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: "Armando Stellato" <starred@tiscalinet.it>,
   "SWI Mailing List" <prolog@swi.psy.uva.nl>
Subject: Re: [SWIPL] How may I leave a PCE window available for input while a server is running on it?
Date: Thu, 27 Sep 2001 09:28:50 +0200
X-Mailer: KMail [version 1.0.29.2]
Content-Type: text/plain
References: <3B77BB2F.4F1B3E45@tiscalinet.it> <01092616590902.19526@gollem> <001e01c146a1$c4cddfb0$295450a0@info.uniroma2.it>
In-Reply-To: <001e01c146a1$c4cddfb0$295450a0@info.uniroma2.it>
MIME-Version: 1.0
Message-Id: <01092709304500.25592@gollem>
Content-Transfer-Encoding: 8bit

On Wed, 26 Sep 2001, Armando Stellato wrote:
>Thank you for your answer.
>Just This morning i found an alternative solution, take a look and tell me
>if it sounds "good".
>I found the class timer (in xpce) and used it to send a message to prolog
>every #milliseconds, letting @prolog use the predicate dispatch
>for client-waiting.
>In this way, the window is not busy anymore and, another important thing,
>while timer continues to make prolog listen for clients, the predicate
>dispatch can then deal with every client that connected to the server.
>So, while SWI-prolog on windows is not multithreaded, the use of XPCE can
>start multiple parallel prolog predicates from the same application, this is
>kind of multitasking...even on windows...
>This fact, combined with the broadcast-library providd with XPCE, can give
>life to a complex agent-based environment!!
>This the portion of code I modified wuth the introduction of the timer
>class:
>
>dispatch(_GUI) :-
> new(@dispatch_timer,timer(0.02,message(@prolog,dispatch1))),
> send(@dispatch_timer,start).
>
>/*
> send(GUI,synchronise),        this portion of code is no more needed
> send(GUI,flush),
> dispatch1,
> !.
>*/
>
>dispatch1 :-
> findall(WriteStream,
>agents:connection(_ClientId,_Socket,WriteStream,_ReadStream), Clients),
> listen_stream(Server),
> wait_for_input([Server|Clients],ReadyList, 0.015),
> (ReadyList \= [])
> ->
> format('ReadyList is: ~w~n',ReadyList),
> process_listen_queue(ReadyList)
> ;
>% write(waiting),nl,flush_output,
> true.
>
>
>Do you think it is a good solution???

Workable.  In general it is better to base networking functionality in
XPCE graphical application on class socket.  See the skeleton HTTPD
class in the XPCE library as an example.

	Regards --- Jan

