Getting started on LiveCode server

Are you using LiveCode to create server scripts or CGIs?

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
mvillion
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 103
Joined: Sun Feb 24, 2013 12:29 pm

Getting started on LiveCode server

Post by mvillion » Thu May 16, 2019 9:59 pm

HI

I have written a number of apps in LC for Windows, Mac and iOS. All good and they work nicely.
I now need to make a web portal equivalent of those apps.

I am not a web developer so I was thinking the best way to tackle it was to have the GUI as one component and an 'engine block' that would do the heavy lifting of the processing of the data in the data base as a back end component - away from the web side of things.

My thinking is I can create a clunky (but functional) version of the web app to start with where options are selected and a block of data is passed to the engine block which will process it and return results that are then displayed by the web side of things. If the portal starts to gain interest, I can pay for a professional web developer to create a slick from end but the back end would no need to change.

I am happy with this architecture but I am struggling to find any documentation of guides about how to build such a beast. The available tutorials are incredibly basic
http://serversamples.livecode.com/ and really provide almost no help.

I have purchased LC server hosting ready for this project but I am struggling on where to start.

Even some outline of how to get a web page to send a block of text to a LC stack in JSON format and to retrieve a block back that it could process would be a huge help. Actually, anything would be a huge help as the level of documentation is slim. I am even willing to buy a book if there is a good one.

I am not massively tied to the architecture I have described above but don't know where else to start.

Are there any people out there with experience in creating web portals, I am willing to pay for some of your time to talk through architectural design principles etc, just so I can get going.

Cheers
Matt

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6624
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Getting started on LiveCode server

Post by FourthWorld » Fri May 17, 2019 12:41 am

One of the challenges with writing documentation for something as vast as what can be done on servers is just that, it's vast.

You did the right thing seeking guidance here: you have a specific need in mind, and we can help you solve it.

Can you tell us more about the data and the work that needs to be done on it? For example, are you using the server because it has other data to be combined with the data you send it, or simply as a way of taking work off the device? What is a typical amount of data you'd be sending? Does the back-end require a database?

There's more, but this will get us started.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 824
Joined: Fri Aug 15, 2008 7:15 am

Re: Getting started on LiveCode server

Post by bangkok » Fri May 17, 2019 3:04 am

First, like Richard said : hang on.
:)

Like everything else, what looks kind of "blurred" now and even frustrating... eventually will appear in full light, and like a famous ancien Greek, you will shout "Eureka !".

Here is a "core" for a web page that will send some data to the server.

2 ways to do that : GET and POST

In your case, POST seems more appropriate (long string of characters in JSON)

This page will mix HTML commands and LiveCode commands :
-a form linked to an input field (to type some data)
-a button ("send data")
-and a LC script (located on the same web page) that will catch those data and do something with them.

You will have to mix HTML scripts with LC scripts. That's the key.

You say that you have a LC Server hosting plan ? That's perfect (no need to install the lot).

So here is a simple ".lc" page :

Code: Select all

<?lc
put $_POST["name"]  into tName
put $_POST["birthdate"] into tBirth
put $_POST["done"] into tDone 

### HANDLE ERROR MESSAGES
if $_GET["D"]=1 then put "TYPE SOMETHING !"
if $_GET["D"]=2 then put "YOU FORGOT BIRTHDATE!"
if $_GET["D"]=3 then put "YOU FORGOT NAME!"

### WE CHECK CONTENT OF POST, BUT ONLY IF DONE VAR = 1
if tDone=1 then

if tName is empty and tBirth is empty then
put new header "Location: helloworld.lc?D=1"
put "sorry"
end if

if tName  is not empty and tBirth is empty then
put new header "Location: helloworld.lc?D=2"
put "sorry"
end if

if tName  is empty and tBirth is not empty then
put new header "Location: helloworld.lc?D=3"
put "sorry"
end if

end if

### POST DATA ARE OK, TIME TO PRCOESS THEM
if tName is not empty and tBirth is not empty then
put "<font color="&quote&"red"&quote&">CONGRATULATIONS</font><BR><BR><BR>"
put "Your name is : "&tName
put "<BR><BR>"
put "Your birthdate is : "&tBirth
quit
end if

?>
<HEAD>
<TITLE>HELLO WORLD APP</TITLE>
</HEAD> 
<h2>HELLO WORLD APP</h2>
<B>Type your name and your birthdate</B>
<BR><BR>
<form action="helloworld.lc" method="post" autocomplete="off">
<input name="name" type="text" size="30">
<input name="birthdate" type="text" size="12">
<input type="hidden" name="done" value="1" />
<button type="submit" name="submit" value="Envoyer">SEND DATA</button>
</form>

<?lc
After that, you can explore other "flavors".

For instance the same script but without an input field on the web page, but instead a stack (app) that will send the data directly to the LC Server page (using POST command) for data processing :

Code: Select all

post tMyData to URL "http://www.mysite.com/helloworld.lc"
Good luck.

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 306
Joined: Tue Apr 10, 2012 9:18 am

Re: Getting started on LiveCode server

Post by ghettocottage » Fri May 17, 2019 9:12 pm

I second everything that @FourthWorld just mentioned and asked in his reply.

I have used something very close to what you described on various database projects. The Livecode/MySQL server has all of my scripts and such, and the app just sends a specific request to the server and gets a reply with the data needed, or updates the database, etc. (basically just wrote my own API)

I generally set this up with an OpenVPN tunnel on the server, so the only way to access it if you are connected to the VPN...an office can be connected to the VPN and have full access.

Works great! There are other ways of securing it, but the VPN works well for the small-office scenarios I set this up for.

mvillion
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 103
Joined: Sun Feb 24, 2013 12:29 pm

Re: Getting started on LiveCode server

Post by mvillion » Fri May 17, 2019 10:21 pm

Hi peoples

I really appreciate the time you spend on answering my questions.

So. I think I need to be clear about what I am thinking.

I have written apps, BUT they no longer suit the needs and need to be disregarded in the context of the move to a portal version of the software. Very useful LC coding experience however I have to park them now and move on to the online world and leave my babies behind. *Sniff*

What I am thinking is:
-The User will use a standard web browser to interact with the web application hosted in LC land.
-I envisage the web code to interact with the user and submit the raw data to the engine block in the back end.
-The engine block will churn and return results
-The web code would take the results and render them in a suitable format for the user to understand.
-I was thinking that there could be templates for the pages to be displayed and the web code would use the template and mix the returned data to make a useful page.

So
In my mind I had a CGI LC web engine that would create pages for the user and transmit them via HTML.
The web engine would handle the user authentication and access list and populate the 'query' to into a data package that was transmitted to the engine block.
The engine block would then process the preformed request and return the processed data. As the engine block is only allowed to accept certain types of queries and limit the number of returns accordingly, it means that the back end database cannot be queried directly, if the web component was to be hacked.

Expanding this.
Is there a way to write a LC CGI code to generate webpages that display data, including images, button etc and waits for user input then when the user presses submit.
Transmits a block of data to the Engine Block (Which is ready to receive a data block) [No idea about how to set this up] which
Transmit the returned answer to the CGI web engine which
Renders the returned results against a pre-formated web page template. (A layout that scales to the amount of data that is required basically). This means the controls on the template would be looking for data to be returned from the engine block. which
Triggers an update to the web page for the user to see which then (Rinse and repeat)


Imagine a 'hello world' for this architecture.

-User authenticates to the app and is displayed a web page with a graphic and a 'show me greeting 1' button.
-User presses the 'show me greeting 1 button'
-The web engine packages the word 'Greeting-1' and transmits it to the engine block in the format of a data package
-The engine block receives the data package and looks up the 'Greeting-1' query and gets back the answer 'Hello World' and template '1'
-The engine block sends the new data package to the web engine
-The web engine receives the reply data package, works out the layout of a page for template '1' and puts the returned string 'Hello world' on that page and renders a page that
-The user gets to see in their browser.

If I have that skeleton, I could build the full application.

Or am I totally off base here and have gone completely mad! (Which is quite possible)
(I feel like my first day in LC land all over again!)


Cheers
Matt

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 306
Joined: Tue Apr 10, 2012 9:18 am

Re: Getting started on LiveCode server

Post by ghettocottage » Sat May 18, 2019 12:13 am

It sounds like you just described a CMS or web-framework.

For a Framework, Revigniter looks promising, but I have not used it yet:
https://revigniter.com/

I do not think there is a Livecode CMS at the time, but I seem to remember someone writing some Livecode/Wordpress API. I think this is it:
https://github.com/digitalpomegranate/l ... wp-restapi

mvillion
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 103
Joined: Sun Feb 24, 2013 12:29 pm

Re: Getting started on LiveCode server

Post by mvillion » Sat May 18, 2019 8:14 am

Thanks. Really appreciate the steer. I will go and investigate. (At least I have some bread crumbs to follow now)
:D :D :D :D :D :D

Maybe I will need to write my own.. Bugger.

Ok. So. To a slightly different question.

Communication between stacks.
Is there an 'elegant' method to pass messages between stacks, running on different servers?

Generation of webpages with images etc
Does a CGI allow the creation of a web page with rich content? (The sample script I have seen just had 'Hello world')

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6624
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Getting started on LiveCode server

Post by FourthWorld » Sat May 18, 2019 9:02 am

mvillion wrote:
Sat May 18, 2019 8:14 am
Communication between stacks.
Is there an 'elegant' method to pass messages between stacks, running on different servers?
What is the relationship between the servers?

Independent of language, in general communications between computers uses sockets. LiveCode supports sockets well.

Over those sockets, the specifics of the communication will be defined in a protocol. In most cases (there are exceptions), that protocol is either HTTP, or some custom protocol which could just as likely have been HTTP but the designer wanted to work too hard. :) LiveCode supports HTTP and HTTPs well.

HTTP is pretty lightweight, and very flexible. Header requirements are minimal, but extensible as well, so you can attach many metadata your application needs, keeping it separate from the payload.

And as a request-and-reply protocol, it covers the vast majority of use-cases very well. Some things like streaming require something other than a request-and-reply protocol. but for most comms the model lends itself well to crafting data conversations, if you will, in which each side takes a turn speaking and then waits for the other to respond.

In fact, HTTP can cover such a broad range of use--cases, it'll be helpful to learn more about the relationship between your servers to advise best on how to set them up.

For example, if the server-server comms are a form of backend behind a load balancer, you can take advantage of an always-on connection that wouldn't be needed or even often desirable with client-server.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

mvillion
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 103
Joined: Sun Feb 24, 2013 12:29 pm

Re: Getting started on LiveCode server

Post by mvillion » Sat May 18, 2019 2:03 pm

Cool. Now we are getting somewhere.

I checked out the lesson on sockets and the examples look workable. I can translate that into meaning and my own code. This means I know how to write the backend and the interconnect to the front end. Excellent.

So, my last challenge is the web front end.
I have some experience with assembling web sites using traditional structures but what I need this time is a web application. Some web application engine that can render a page containing text, pictures and images etc and respond to a user's input. I see that CGI type server design is probably the best way to do this but the only example I have seen just places text 'Hello world' on a page.

Is there a basic lesson somewhere which shows the most basic interaction with a user.
-Display page. with text, tables, pictures and buttons
-User clicks on a button
-Page updates

I know how to do it in LC for iOS, Mac and Windows but I don't know the approach for a web app, as there is a browser to interact with.

Any ideas?

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 306
Joined: Tue Apr 10, 2012 9:18 am

Re: Getting started on LiveCode server

Post by ghettocottage » Sat May 18, 2019 10:27 pm

Eventually you will probably want to use a framework like Revigniter, but it is my opinion that you would progress much faster in this if you start by writing your own structure or copying a basic structure and getting the hang of how website applications work.

I have a basic structure that I use as a starting point that I can copy and post here if I have time later this evening.

In the meantime you will want to brush up on your HTML, CSS and JS. Livecode Server is very similar to PHP and can be used in most of the ways that PHP is used (although I like coding in Livecode better)

mvillion
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 103
Joined: Sun Feb 24, 2013 12:29 pm

Re: Getting started on LiveCode server

Post by mvillion » Sat May 18, 2019 10:36 pm

Thanks to everyone for the support.

It is great to see the community working so well (and I really appreciate the assistance)
:D :D :D :D :D :D :D :D

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 306
Joined: Tue Apr 10, 2012 9:18 am

Re: Getting started on LiveCode server

Post by ghettocottage » Fri May 31, 2019 4:02 pm

I wanted to post and let you know I am still working on a basic framework to post for people to use as a starting point.

The topic comes up quite often, so I wanted to have a good working example of interacting with Livecode, Livecode Server, and a Database.

It will probably take me another week to finish and post it. I take care of my 2yr old all week so I do this in my spare time.

Post Reply

Return to “CGIs and the Server”