Jan, thanks for your comments. I think the scenario is important
enough to warrant work in the area, so, guided by your advice, I may
give it a try (a couple of code snippets detailing some aspects of
your proposed solution would be helpful though!).
> More in general, I'm looking for good examples for this (and other)
> packages. If you have things to share or are willing to write examples,
> please share them.
I recognise the need for good examples, so to the best of my
abilities, and with some guidance, I'm willing to contribute. See my
next message!
Best,
Torbjörn
On Fri, Jun 19, 2009 at 9:40 AM, Jan Wielemaker<
J.Wielemaker@...> wrote:
> On Thursday 18 June 2009 14:57:27 Torbjörn Lager wrote:
>> Hello,
>>
>> Please have a look at the following code:
>> :- use_module(library('http/thread_httpd')).
>> :- use_module(library('http/http_dispatch')).
>> :- use_module(library('http/json')).
>> :- use_module(library('http/http_json')).
>> :
>> :- http_handler('/doit', doit, [spawn([alias(test)])]).
>>
>> doit(_Requestl) :-
>> reply_json(json([a=result])),
>> thread_get_message(Event),
>> process(Event).
>>
>> :- http_server(http_dispatch, [port(5000)]).
>>
>> The call to thread_get_message/1 blocks (as it should), which seems to
>> imply that no JSON is returned to the browser (until I kill the
>> server). Does it have to be that way (I don't see why)? Is there any
>> way I can send JSON to the client and still keep the thread on the
>> server running?
>
> Not easily. The whole infrastructure is designed to deal with finishing
> the reply on completion of the handler. What you can do is enable
> session management (you need that anyway) and create a thread that is
> associated to the session. That is where you have the state-full
> computation and you send messages back and forth between the HTTP
> handlers and the session thread to communicate queries and results.
>
> Would be nice to have a demo using this scenario in the HTTP server
> examples directory ...
>
> More in general, I'm looking for good examples for this (and other)
> packages. If you have things to share or are willing to write examples,
> please share them.
>
> Cheers --- Jan
>
>> (What I'm trying to find here is a way to ask for one solution at the
>> time for a Prolog goal entered in a web interface. I have written code
>> that should have worked, had only the above worked... Maybe there are
>> other ideas for how to accomplish what I want to do? I've looked at
>> Uwe Lestas N-Queens demo, but it striked me as too complicated, and I
>> really would like to work against the SWI webserver...)
>>
>> Thanks in advance!
>>
>> Best regards,
>> Torbjörn
>
>
>
>
--
Torbjörn Lager
Professor of General and Computational Linguistics
Department of Philosophy, Linguistics and Theory of Science
Box 200, SE-405 30 Göteborg, Sweden
Phone: +46317864413
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog