Recent

Author Topic: Network service  (Read 1901 times)

michoux

  • Full Member
  • ***
  • Posts: 112
Network service
« on: November 23, 2022, 12:00:16 pm »
Hello,

I was requested to build an application which will print out accreditations for some sport event.
The problem is following, the front end is made by another company, and it is based on web application.
Our stuff logs to accreditation web app and selects let say "Jon Doe" and there is a print button .... now ... my idea was to create a service with Lazarus which will listen
on some port on particular laptop ... receive the data XML, JSON ....  and then print this data in special format, which matches the layout of accreditation ...
Is this even possible? I am not much of a web developer so before I ask this company I ask here for any ideas ....
Additional question is on report designer.
In the past I worked with delphi and rave reports, what would be best report designer for Lazarus, I need to print on exact layout with picture name and some other things.


Regards Mich

michoux

  • Full Member
  • ***
  • Posts: 112
Re: Network service
« Reply #1 on: November 24, 2022, 08:35:14 am »
Ok, this look to complicated.

I have another idea. I need a signal from web site that my data is ready and I can go and take it.

Our stuff click a button on web, on the web site they generate JSON data of particular person.
New tab opens in browser (http://localhost:8080?ID=33), This sends ID 33 to my local service.
I fetch the JSON from web parse it, print it ... ...

Would this be ok? 

Regards Mich



egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: Network service
« Reply #2 on: November 30, 2022, 01:04:12 am »
What do you mean by "your stuff click a button"?  What is your stuff?

If you want to build a Lazarus application, you can use THTTPClient, with which you can send requests to and receive responses from webserver. Then you can do whatever you want with it.

Or to make "clicking a button" send some commands to your application, you may build your own webserver and set the button's action property to your webserver.

dbannon

  • Hero Member
  • *****
  • Posts: 2778
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Network service
« Reply #3 on: November 30, 2022, 03:09:21 am »
stuff >> staff ?

Listening in on the conversation between your existing (third party) client and the (third party) Web Service would be a bad idea, if you can, you should stop using it altogether !

My thought is, you have put your data in the hands of a commercial operation, you now must work with them. Ask them to provide an additional service whereby you can ask for the data for Jon Doe, get it as you say, as json and then, now you have it, do with it what you want.

But without the cooperation of the third party, you are in trouble.

Do you have a plan about what happens to your data if the company holding goes out of business ?

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

af0815

  • Hero Member
  • *****
  • Posts: 1284
Re: Network service
« Reply #4 on: November 30, 2022, 07:27:08 am »
If i read the description:

a ) a web app have a button
b ) if somebody press this 'print button' a action is generated and the data is sent to your application

1 ) How is the data transfered - what kind of request is generated ? Must you poll and get or is the data pushed to your app ?
2 ) is there any handshake needed ? You must confirm if the data is read and/or printed correct

As egsuh wrote, your app can be a webservice, and is sitting and waiting for data. If data arrive you print and aknowledge the printout back.

More Questions are, is your app visible with a gui (using LCL) or like a service/demon (without LCL) working hidden. 
regards
Andreas

michoux

  • Full Member
  • ***
  • Posts: 112
Re: Network service
« Reply #5 on: December 02, 2022, 06:15:02 pm »
1 ) How is the data transfered - what kind of request is generated ? Must you poll and get or is the data pushed to your app ?
  This is not done. At the moment, as I said, in particular web page there is a print button. But we can not use this to print on local printers, also company which developed web part does not want to deal with this ...
   Web company which developed this web app, will cooperate and provide help ...
   They can dump the JSON data somewhere, when print button is pressed, and I can fetch them with my application and then do my stuff with printing the data.
   They can also dump the JSON on to local laptop with javascript ....


2 ) is there any handshake needed ? You must confirm if the data is read and/or printed correct
  All I need is to get somehow info that someone pressed the button "print" then I can trigger some action to get the data.
  I was thinking that I could check for a particular file on disk, which can be I think generated with javascript, when somone clicks the print button, if file is there then I can fetch data ... After I delete the file and wait for new ....

Rehg

michoux

  • Full Member
  • ***
  • Posts: 112
Re: Network service
« Reply #6 on: December 02, 2022, 06:29:22 pm »
- -What do you mean by "your stuff click a button"?  What is your stuff?

There will be some people responsible to print the  accreditation.
Process is like this.
 - They navigate to web page, where they select particular person for which they want to print the accreditation.
 - They press the print button on web page.
 - This button then somehow handshakesu with local app on laptop, this triggers local app to either go and get the data from web (JSON, XML )
    Or with java script data is dumped to local disk ...

If you want to build a Lazarus application, you can use THTTPClient, with which you can send requests to and receive responses from webserver. Then you can do whatever you want with it.
  - We do not have data locally, it is easy to use already built service from web.

I just need some kind of signal that print button was pressed, after that we are ok ...

egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: Network service
« Reply #7 on: December 04, 2022, 09:32:53 am »
The simplest approach might be pressing the button collects related data, produce a JSON file, and email the file to you. Then you'll know that the PRESS button was pressed.  Not sure I'm understanding you correctly.
« Last Edit: December 04, 2022, 09:49:42 am by egsuh »

michoux

  • Full Member
  • ***
  • Posts: 112
Re: Network service
« Reply #8 on: December 04, 2022, 10:04:34 am »
Hello,

Thank you all for you help, it is yes a strange case I understand.
I spoke with guys who own the web part.
They said that some tests were made from their side and they are able to contact localhost service with JavaScript.

So process would be like this.
- Print referent uses a print button on web service.
- Json data is generated, and pushed to referents laptop over localhost web service.

So What I would need to do is to make a web service which would listen on local laptop and would consume a Json data from them.
Then This data is parsed and printed - all automatically ....

What you recommend for this? Create a local web service with fpweb?

Regards Matija

egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: Network service
« Reply #9 on: December 04, 2022, 11:44:37 am »
I don't understand. localhost is the PC itself that is running any other program, e.g. browser.  Their accessing localhost doesn't mean anything.

Anyway, based on what you said, building a webserver from your side is the easist, I think.

Pressing the PRINT button will do followings:

   1)  collect relevant data
   2)  make a JSON file
   3)  upload the JSON file to your webserver.

Your webserver will receive the file, parse and print it.

Writing such a simple webserver in Lazarus is quite simple. But you have to set it up and run it.

michoux

  • Full Member
  • ***
  • Posts: 112
Re: Network service
« Reply #10 on: December 04, 2022, 12:14:40 pm »
Hi,

Thanks, It is something like this yes.
What tools to use to build simple web server?
I created a web server with Lazarus before.

egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: Network service
« Reply #11 on: December 04, 2022, 01:16:19 pm »
You only have to install weblaz package. Here are documentations. You won't have much difficulty if you have experience of creating web server in the past.

https://wiki.freepascal.org/fcl-web
https://wiki.freepascal.org/fpWeb_Tutorial

michoux

  • Full Member
  • ***
  • Posts: 112
Re: Network service
« Reply #12 on: December 04, 2022, 01:40:40 pm »
Sorry, I wanted to say I never created a http server in Lazarus.
I guess there are some examples on forum, with get function.
I would not need any pages displayed, just to get the json data
 posted

egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: Network service
« Reply #13 on: December 04, 2022, 01:45:15 pm »
There are examples in the documentions I mentioned.

michoux

  • Full Member
  • ***
  • Posts: 112
Re: Network service
« Reply #14 on: December 04, 2022, 01:54:41 pm »
Great.
How to test such app?
Can I use curl or similar?

 

TinyPortal © 2005-2018