Using Browser as Front End
Haitao Zhang <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAFUyvhpuv+wb5JC8C_vCCBb75gQzob_BbEznYtvELRjGiTUAAg@mail.gmail.com> |
I know using browser as a front end is not a new idea but I found out recently that WebSocket makes pushing data to browser very easy to do. My personal interest is to use the javascript libraries supported by browsers (D3 in my case) for visualization, while retaining control in a Prolog console -- so I don't have to write a web server. This turns out fairly straightforward. I know that SWI does not yet support WebSocket, but one can write a simple man-in-the-middle server easily in anything that supports WS. My first try was with nodejs. Then I tried with Emacs/Elisp since I access SWI from Emacs with ediprolog. Both worked out well in my simple use case, where it is just one way traffic from Prolog to the browser. But as a proof of concept I see it as a good sign for more ambitious undertakings. My setup is like this: start servers (WS and TCP) in the host platform. I use emacs but nodejs also works with little coding. Connect the browser to the WS server (through embedded javascript in a local html file). Connect Prolog to the TCP server. The host platform then simply copies any data coming in through the TCP socket over to the outgoing WebSocket. As I said I only implemented the half duplex part for my personal use, but servers should be neutral on the direction of flow. I would have to set up my Prolog client to handle async data and have not got around to it as I am happy with running things from my ediprolog console, which runs synchronously. Above the data layer I wrote some js client code to display data, and I then send over data from Prolog (encoded in json with embedded dispatching information) and have the data rendered in the browser. I also use the same websocket to update my js client code whenever I have a need to (like after creating a new display function). So the REPL is complete for both js and Prolog. My primary intention is just to share the idea and hopefully someone will find it helpful. On a more tentative note, Carlo Capelli has recently ported the Prolog console to Qt. Is there an interest in creating a javascript based frontend for SWI? There are a lot of UI and graphics libraries available through js. With Websocket async two way communication is easy as well. Just a thought, Haitao Zhang -------------- next part -------------- HTML attachment scrubbed and removed