Re: Using Browser as Front End
Carlo Capelli <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CABty9wzcdchiAuefzxVen5xhhRSvFDegAg1ZbtW1qAso1bYz8A@mail.gmail.com> |
2013/12/14 Haitao Zhang <[email protected]> > 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. > > Very interesting, thanks for sharing. > 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. > I'm a bit ashamed I didn't know about WebSocket, but after some read, I'd like to try to implement a WS REPL. I guess that building WS in SWI-Prolog should be the preferred way, but to start with something I'm comfortable, I've got some support from Qt community - both QWebSocket <https://github.com/gustavosbarreto/qwebsocket> and QtWebsocket <https://github.com/ant-lafarge/QtWebsocket> are available. QWebSocket has less requirements, I'll begin with this one. Server side, just bridging IO should work... Client side, I find QtWebKit functional, for instance getting offline plDoc (F1 help on cursor) it's banal. Pack(webconsole) then it's the first choice, but - i think - will need some change to run a console 'stream mode'. I'd like to see it integrated with CodeMirror, should be nice and functional, just classify the HTML input area could work. Anyway, pqConsole currently doesn't depend on QtWebKit (~30Mb spare), but since it outputs HTML (with Prolog controlled links - visible 'commands') could be an interesting 'intermediate point'. bye Carlo Just a thought, > > Haitao Zhang > -------------- next part -------------- > HTML attachment scrubbed and removed > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > -------------- next part -------------- HTML attachment scrubbed and removed