I need a basic example of using a "Streaming App"

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 366
Joined: Tue Apr 10, 2012 9:18 am

I need a basic example of using a "Streaming App"

Post by ghettocottage » Fri Oct 07, 2016 3:29 am

In more than one post, Richard Gaskin has described a Streaming app (one example of a thread that touches on this: http://forums.livecode.com/viewtopic.ph ... 2&p=146017 )

Has anyone out there in Livecode land used this method successfully? If so, are you willing to post a basic example of this?

There is an example in Livecode 8, under plugins>GoLiveNet which is really great, but the script that downloads the stack and uncompresses it is rather complex and I would just like to do a simple starter for this before I attempt additional features. I picked through it a bit but have not quite managed to unlock the secrets just yet. I need a little help.

I have a remote server with Livecode 8 server on it. What will my script look like that downloads and opens the stack on my server, and then closes it when through?

Any help is appreciated!

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

Re: I need a basic example of using a "Streaming App"

Post by FourthWorld » Fri Oct 07, 2016 4:21 am

ghettocottage wrote:There is an example in Livecode 8, under plugins>GoLiveNet which is really great, but the script that downloads the stack and uncompresses it is rather complex and I would just like to do a simple starter for this before I attempt additional features. I picked through it a bit but have not quite managed to unlock the secrets just yet. I need a little help.
I should simplify that. It's old code that used to do more than it now needs to, and is needlessly complicated. My apologies.

Here's an exercise to get you started:

1. Upload a LiveCode stack file to a server

2. In your local Message Box, type

Code: Select all

go url "http://www.yourdomain.com/path/to/file.livecom"
If your stack is really large you can use the load command with a progress bar and other goodies, but in both of the two projects I run where we use downloaded stack I've found that since we're just downloading the stack file it's pretty small, and the "go" command works just fine by itself since the transfer time is usually just a second or two.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: I need a basic example of using a "Streaming App"

Post by ghettocottage » Fri Oct 07, 2016 4:47 am

Here's an exercise to get you started:

1. Upload a LiveCode stack file to a server

2. In your local Message Box, type

Code: Select all

 Select all
    go url "http://www.yourdomain.com/path/to/file.livecom"
Okay. I am kicking myself just now.

You had actually posted the same code in another thread, and I was trying that, and many variations with no luck. I figured I was missing some vital piece of information..

Turns out that I had added some rules in my .htaccess to prevent access to the stacks folder, and forgot to remove those rules when it came time to start working with the stacks.
I just removed those rules and my stacks pop-up immediately from that code.

Thanks!! Next time I will double check my server configuration before posting.

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

Re: I need a basic example of using a "Streaming App"

Post by ghettocottage » Fri Oct 07, 2016 5:05 am

I should simplify that. It's old code that used to do more than it now needs to, and is needlessly complicated. My apologies.
Just exploring the idea, and looking through your code, how far down would you simplify that if you were re-doing it?

It looks like it has some checks in case the download fails, or someone cancels the downloads, and then moves the launcher stack to the background and sets the downloaded stack to the front, and then some other things that I do not understand that look terribly impressive.

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

Re: I need a basic example of using a "Streaming App"

Post by ghettocottage » Fri Oct 07, 2016 3:49 pm

...have been spending more time playing around with the idea. I have to say this works very well, and has many advantages over having a static file that needs to be updated on every device it runs on.

Is there any down-side? I am trying to think through any possible issues:
  • *Since the application I am building relies on a remote database, it requires a connection regardless, so not being able to launch if there is no internet is not an issue.
  • *For security, I have this particular server only accessible via VPN, so the stack on the server is not publicly available.
  • *If I understand this concept correctly, the stack is downloaded temporarily to each device that opens it, so multiple people using it at once will not be an issue.

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

Re: I need a basic example of using a "Streaming App"

Post by FourthWorld » Fri Oct 07, 2016 7:36 pm

ghettocottage wrote:
  • *For security, I have this particular server only accessible via VPN, so the stack on the server is not publicly available.
VPN is a good option. In most of the projects I've used this on I also need authentication and other backend services, so I keep the stack files outside of the web root folder and serve them as binary files from an LC Server CGI.
  • *If I understand this concept correctly, the stack is downloaded temporarily to each device that opens it, so multiple people using it at once will not be an issue.
Yes, when a stack us loaded from a remote source it has no file name and exists only in RAM. And like a web page or most other network-delivered resources it's a copy of whatever's on the server, so each user has their own copy and they don't interfere with one another.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: I need a basic example of using a "Streaming App"

Post by ghettocottage » Mon Jul 03, 2017 11:24 pm

@FourthWorld
VPN is a good option. In most of the projects I've used this on I also need authentication and other backend services, so I keep the stack files outside of the web root folder and serve them as binary files from an LC Server CGI.
Richard,
I know this is an old thread, but I was wondering if you could elaborate a little on this comment that you serve the Livecode Stack as a binary file. Do you mean that you use a file-server rather than web-server on the VPN to serve the stacks?

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

Re: I need a basic example of using a "Streaming App"

Post by FourthWorld » Wed Jul 05, 2017 6:31 am

Web server. Given the lightweight simplicity of HTTP I rarely use anything else.

Just as a web server can read image files from disk and send them over the wire to the requesting client, they can deliver any other binary data the client app can handle. When that client is made with LC, stack files are a natural fit.

I'd you'd like I can turn up my version is mchttpd, socket server that handles HTTP. It's not great for production except maybe in very specialized setups, but it's a great way to learn how HTTP works so your can later use Apache, Lightly, Nginx, or anything else with confidence.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: I need a basic example of using a "Streaming App"

Post by ghettocottage » Wed Jul 05, 2017 9:07 pm

I'd you'd like I can turn up my version is mchttpd, socket server that handles HTTP. It's not great for production except maybe in very specialized setups, but it's a great way to learn how HTTP works so your can later use Apache, Lightly, Nginx, or anything else with confidence.
Yes, that would be great. So far I have a launcher app that uses:

Code: Select all

on openStack
   go url "https://db.myserver.com/stacks/db.livecode"      
   close stack "launcher"
end openStack
This works great, but I have not been able to figure out how to deliver those stacks from outside the webroot folder like you had mentioned.

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

Re: I need a basic example of using a "Streaming App"

Post by FourthWorld » Wed Jul 05, 2017 9:30 pm

Do you have LiveCode Server or other flexible scripting language set up as a CGI on your server?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: I need a basic example of using a "Streaming App"

Post by ghettocottage » Thu Jul 06, 2017 4:07 am

Do you have LiveCode Server or other flexible scripting language set up as a CGI on your server?
Indeed I do

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

Re: I need a basic example of using a "Streaming App"

Post by FourthWorld » Thu Jul 06, 2017 6:54 pm

Your CGI script can just read the file. Use binary mode, then just send it back to the requesting client using "put" like you would any other data.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: I need a basic example of using a "Streaming App"

Post by ghettocottage » Thu Jul 06, 2017 8:35 pm

FourthWorld wrote:Your CGI script can just read the file. Use binary mode, then just send it back to the requesting client using "put" like you would any other data.
Sorry, I have been experimenting but cannot seem to make this work. Can you give me an example of what the CGI script might look like?

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

Re: I need a basic example of using a "Streaming App"

Post by FourthWorld » Thu Jul 06, 2017 9:28 pm

Code: Select all

put url ("binfile:path/to/somestack.livecode) into tStackData
-- Always check for errors with file I/O:
if the result is not empty then
  put "Error: "& the result &&"("& sysError() ")"
  quit
end if
-- Deliver the goods:
put tStackData
quit
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: I need a basic example of using a "Streaming App"

Post by ghettocottage » Thu Jul 06, 2017 10:20 pm

That works!

I was very close with the script I was trying, but I had to set permissions on the parent folder of where my external files are so the apache-user could have access (where webroot is /var/www/webroot and stacks are at /var/www/stacks)

fixed with
chown -R www-data:www-data /var/www &&chmod -R 775 /var/www

and now the CGI script loads the stack from a folder outside of the web-root.

Thank you so much!

Post Reply

Return to “CGIs and the Server”