George Thomas writes:
Hi - Any and all answers to this are most welcome: is it possible to run ciao prolog in a 'server mode' and support multiple concurrent user access (say, via http clients or sockets)? What are the easiest approaches to accomplish this?
If what you want to send/receive are Prolog calls, the easiest way is to use active modules: you will be able to issue a Prolog call in an executable (a program) so that the call is effectively run by a different executable (an active module). Thus, in short, an active module is a server of Prolog calls. Have a look at library actmods and the corresponding chapter of the manual.
If you want a server of anything other than Prolog calls, you can do it simply with sockets. The following code starts a server on a socket Port:
:- use_module(library('sockets/sockets_io'),[serve_socket/3]).
main([Port]):- atom_codes(Port,Codes), number_codes(N,Codes), bind_socket(N,5,Socket), serve_socket(Socket,server,catcher).
server(Stream):- there_is_a_connection_so_serve_it(Stream).
The communication is open on a Stream, and you simply need to read from and write to the Stream. Library sockets_io is a recent development. It is not in the current distribution of Ciao, but we can send it to you, if you're interested.
To serve requests concurrently all you would need to do is:
:- use_package(hlc).
server(Stream):- there_is_a_connection_so_serve_it(Stream) && .
Have a look at the manual chapter about concurrency and threads.
We are currently developing a library for HTTP service. It is not finalized but it works to some extent. If you are interested, send me email and I will send it to you.
Is there an efficient mechanism for 'active modules' (discussed in the paper by Daniel Cabeza and Manuel Hermenegildo at the Pillow web site)? Its not clear from the Pillow Reference Library Doc how to do this. I would love to find something more efficient than CGI.
Using the abovementioned HTTP server library you could program your own HTTP server, and you won't need CGIs. For example, you could program your server to directly connect to a process instead of starting a CGI.
If you use a standard browser instead then you cannot skip using CGIs, but you can make the CGI very lightweight by making it simply read the input and pass it to an ever-running daemon that will process it. Then you won't need to start the (probably heavyweight) server each time as a CGI. This was the idea in the paper you mention, if I remember well.
The following code can be used as a CGI that will be executed by the browser upon an HTTP POST request. It simply reads input passed along by the browser and writes the answer back. The computation is done by an active module running as daemon:
:- use_package(actmods). :- use_active_module(daemon,[serve_request/2]).
:- use_module(library(file_utils),[stream_to_string/2]). :- use_module(library(strings),[write_string/2]).
main:- stream_to_string(user_input,StringIn), serve_request(StringIn,StringOut), write_string(user_output,StringOut).
The daemon will be written as a normal module:
:- module(daemon,[serve_request/2]).
serve_request(StringIn,StringOut):- ...
The only thing is to compile it with a particular option (see the manual) for active modules. Then it can be run separatedly.
Paco Bueno ============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------