Subject: Re: [SWIPL] How may I leave a PCE window available for input while a server is running on it?

From: Jan Wielemaker <[email-masked]>
Date: Thu, 27 Sep 2001 09:28:50 +0200

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