Lazarus

Programming => Networking and Web Programming => Topic started by: lainz on July 03, 2018, 07:06:36 pm

Title: Customer Display server and webpage [Solved]
Post by: lainz on July 03, 2018, 07:06:36 pm
Hi,

I need to make a Customer Display, something like is used in the banks or pharmacy for turns, but instead of showing who is next, showing the details of the buy in progress: list of products with price, total, method of payment, etc.

The data is inside a Lazarus application for Windows. I want to make a local web server that shows a webpage with that data, the server need to communicate with the GUI application to update the data.

What do you think will be a good way?

I think this is an option:
- GUI application sends the data to the local server
- Web Page served with the local server do a Get constantly to an endpoint in the same local server to bring the data in JSON, then is parsed and displayed (like for example using AngularJS - is the one I know)

But the main problem is that:
- I need to do Get requests constantly

And is not a problem of updating the list of products, due how is AngularJS is designed, it can update lists efficiently.

This needs to be a webpage, because I can show that information for example in a Tablet, if the commerce doesn't have a second monitor or a hardware capable of having 2 monitors.

Also I will show ads when there is no buy in progress..
Title: Re: Customer Display server and webpage
Post by: taazz on July 03, 2018, 08:41:39 pm
Yes that is the nature of stateless application. Once the html is created there is no state to compare against for changes. You need to re query the data again. Or are you trying to create a known state using websockets to push data back? This will have the side effect of a page that never ends loading.
Title: Re: Customer Display server and webpage
Post by: lainz on July 03, 2018, 09:01:16 pm
The page is only to be seen by the user, there will be no interaction at all, and will be running fullscreen.

And yes, with my idea this will never end loading data, it will be always communicating. I'm just starting the website html + css template, so I've not touched any code yet.

Option 1:
I will not serve static html only, but also JS that will do the 'Get' to a JSON endpoint every say, 4 seconds or less, I already used Brook Framework and works very fast as an endpoint.

So the webpage is only the structure, and that will be changed with the data by AngularJS code.

The delay will be sending the data from the GUI to the server, and from the server to the web app.

Option 2:
The other way is reloading the static HTML entirely made by the webserver, so there's no communication in that way, only a full page reload, no usage of AngularJS.

The delay is only between GUI desktop app and the server, then the build of the HTML, and showing that in the browser.
Title: Re: Customer Display server and webpage
Post by: taazz on July 03, 2018, 09:13:30 pm
The page is only to be seen by the user, there will be no interaction at all, and will be running fullscreen.

And yes, with my idea this will never end loading data, it will be always communicating. I'm just starting the website html + css template, so I've not touched any code yet.

Option 1:
I will not serve static html only, but also JS that will do the 'Get' to a JSON endpoint every say, 4 seconds or less, I already used Brook Framework and works very fast as an endpoint.

So the webpage is only the structure, and that will be changed with the data by AngularJS code.

The delay will be sending the data from the GUI to the server, and from the server to the web app.

Option 2:
The other way is reloading the static HTML entirely made by the webserver, so there's no communication in that way, only a full page reload, no usage of AngularJS.

The delay is only between GUI desktop app and the server, then the build of the HTML, and showing that in the browser.
go with option 2 in both of your cases the server will be hit in intervals for data the difference comes down between a json and a html page, it does not look that big (unless we are talking images).
Title: Re: Customer Display server and webpage
Post by: sash on July 03, 2018, 10:08:51 pm
I'm not sure I got your exact task, but in any case you don't need to refresh whole web page constantly.
There's a "server push" technique, for example a longpoll script.
Title: Re: Customer Display server and webpage
Post by: lainz on July 04, 2018, 02:15:56 am
We're trying now to use websockets with an Indy udp server. To send data directly to the page from the GUI application and process that with angularjs.

Let's see if it works, is far more simple this way.
Title: Re: Customer Display server and webpage
Post by: taazz on July 04, 2018, 03:06:10 am
We're trying now to use websockets with an Indy udp server. To send data directly to the page from the GUI application and process that with angularjs.

Let's see if it works, is far more simple this way.
very interesting, I'd like to have a look on that sample or read a blog post about it, what ever works better.
Title: Re: Customer Display server and webpage
Post by: lainz on July 04, 2018, 04:12:06 am
Well seems that there is only a paid websockets component.

The other component I found is out of date and not working according to the repo readme...

UDP can't be used with websockets.

Maybe with webrtc but I have no idea.
Title: Re: Customer Display server and webpage
Post by: lainz on July 04, 2018, 04:16:20 am
https://github.com/andremussche/DelphiWebsockets
Title: Re: Customer Display server and webpage
Post by: taazz on July 04, 2018, 05:51:30 am
Oh I see. thanks for the info.
Title: Re: Customer Display server and webpage
Post by: DonAlfredo on July 04, 2018, 06:10:04 am
The mORMot has websockets for you !

https://synopse.info/files/html/Synopse%20mORMot%20Framework%20SAD%201.18.html#TITL_150

https://github.com/synopse/mORMot/tree/master/SQLite3/Samples/31%20-%20WebSockets
Title: Re: Customer Display server and webpage
Post by: lainz on July 04, 2018, 03:29:01 pm
Thanks. I will try them.

Edit: Installed mormot with FPCUpDeluxe with my current Lazarus setup, and tested the demo and works fine, thanks  :)
Title: Re: Customer Display server and webpage [Solved]
Post by: lainz on July 04, 2018, 07:44:44 pm
I need a bit more of help, I asked in the mormot forum, if anyone interested
https://synopse.info/forum/viewtopic.php?pid=27640#p27640
TinyPortal © 2005-2018