Creating a local server

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Creating a local server

Post by Simon Knight » Fri Dec 23, 2022 10:38 am

Hi all,

Recently I watched a video by the "Python Programmer", published on Youtube, that showed a simple one line Python Script that created a local server to serve files stored in a single folder to an ipad or similar device connected to the same LAN.

I was wondering how much work it would be to create a similar local server using Livecode. I'm guessing I should be looking at the hpptd library but thought I would ask before fumbling with any code.

Oh, my knowledge of AJAX goes no further than the 1960s kitchen cleaner.
best wishes
Skids

stam
Posts: 2736
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Creating a local server

Post by stam » Fri Dec 23, 2022 11:01 am

Is this not something you'd use LiveCode Server for?

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

Re: Creating a local server

Post by FourthWorld » Fri Dec 23, 2022 5:24 pm

@Skids: Yes, the httpd lib would be a good starting point. I haven't used it as a general web server myself (it's designed primarily to assist debugging mobile apps), but if you run into any snags just let us know. There are a few other httpd servers written in LiveCode, and I have one that's an updated edition of the first, the one that shipped with MetaCard back in the day, updated for compatibility with HTTP 1.1 and with more thorough use of callbacks for a performance boost:
http://fourthworld.net/lc/mchttpd-4W.zip

@Stam: LC Server is designed to run as a CGI under Apache or other server software that supports CGI, like Lighttpd. I haven't used it as a standalone server, and given the differences in the event loop between Server and desktop LC I'm not sure it would work well taking on the server role itself. It might, I just haven't tried. But I have run LC desktop standalones as servers, and using the mchttpd lib I posted above I was delighted to find that in Siege tests I was able to get about 50% of the throughout performance from that humble library as Apache delivers for basic serving of small files.

While it's great to see a script perform half as quickly as a purpose-built compiled app written by specialists, it is only half as quickly, and has nowhere near the scope of features Apache has.

So while I believe writing an httpd server in LC is a fun exercise and can be a good way to learn about HTTP, I wouldn't use a scripted server in a production environment. Apache is freely available, well documented, and quite good, and there are many others as well if you need anything Apache doesn't provide.

That said, I extend this caution only for the commodity role of generic file serving over HTTP.

A more practical setup I and many others have used in production is Apache in the httpd role for generic file severing, with LC Server as a CGI under Apache where special processing is needed. That separation of concerns keeps the boring stuff in boring software <g>, letting the developer focus on the application-specific parts in scripts.

All that said, Skids' request sounds more like fun and learning than any attempt at building the next Google, so a simple httpd server script can be great exercise and can have some practical uses on a home network.

In fact, the more I think about it, I might even recommend the mchttpd stack I'd updated over LC's, if only because Dr Raney designed it for exactly the purpose Skids describes.

And IIRC it may even best the Python demo he saw in one regard: while that demo required writing one line of code, mchttpd requires none - you turn it on and off with a checkbox. :)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Creating a local server

Post by Simon Knight » Sat Dec 24, 2022 8:04 am

Forthworld - thanks for your very detailed response.

I can confirm that I have no plans to take on Google but perhaps I should have explained my objective. Recently I had a conversation where the discussion centred on the potential loss of copyright if images are stored in the "cloud" (remote off base commercial servers). We were talking primarily about Apple and I have checked the T's and C's and basically it does not appear to be an issue. However, I believe there have been some other 'services' that have used subscribers images and data in the past by way of payment.

The conversation coincided with me being given an old ipad which I have discovered is quite useful for viewing images on and also for streaming to a Roku device attached to a TV using AirPlay. I should state that I am not a fan of iOS as the devices appear locked down and I much prefer Android tablets although my ageing hudl from Tesco struggles to stream anything but at least it has a Micro SD card slot and an hdmi port.

Anyway I began thinking of ways of copying images from my computer to the ipad. The obvious solution is to use the Apple designed route of hard disc -> Photos Application ->{ iCloud }-> ipad, PhotosApp -> view. However this seems rather wasteful when the source and the target devices are both on the same LAN so I asked my question. In the process of casting about for alternatives I have discovered that my Draytek router has a built in "smb" server

I will certainly look at mchttpd if only to learn something about http.
best wishes
Skids

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7257
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Creating a local server

Post by jacque » Sat Dec 24, 2022 6:26 pm

Anyway I began thinking of ways of copying images from my computer to the ipad
I can't remember if you're on a Mac but if so, AirDrop is a direct method.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Creating a local server

Post by Simon Knight » Sun Dec 25, 2022 8:16 am

I can't remember if you're on a Mac but if so, AirDrop is a direct method.
Yes I am on a mac, however when I have tried airdrop I have found it to be rather "hit and miss" its o.k. for a few images but give it a larger number then it fails.
best wishes
Skids

Post Reply

Return to “Talking LiveCode”