Websocket client Livecode

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bhall2001
Posts: 107
Joined: Thu Oct 30, 2014 3:54 pm
Location: Manchester, NH

Websocket client Livecode

Post by bhall2001 » Mon Feb 13, 2023 6:14 pm

I've come to the point where I can not wait any longer for an LC websocket library. I need to have a websocket client in a Mac and Windows Livecode app. I have the sending side down it's the receiving of websocket events that I need to implement.

Before I start a proof of concept, I wanted to see what folks think of my logic to get this going in LC. It's a bit of a hack but seems plausible...

- use a hidden browser widget in the app
- write Javascript that handles all things needed for the websocket events listener, code will run in browser widget
- create an LC callback in the websocket event handler that sends the websocket message details to Livecode for processing/action.

My plain is to create an app where I can prove out the above using piesocket.com and the websocket tester they offer.

I've not done anything with JS in a LC client app before. I do a lot with JS in my professional career. I think a callback is possible from JS to LC. That's the one piece I'm a little unsure of.

Does anyone have any thoughts on if my steps seem reasonable? If I can get this working I'll share a write-up and my POC stack for folks to try it out.

Thanks in advance,
Bob
Manchester, NH, US

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Websocket client Livecode

Post by mwieder » Mon Feb 13, 2023 6:33 pm

Bob-

Mark Waddingham keeps saying that websockets are coming "soon", but I think that's a Scottish euphemism that I'm not familiar with. <g>
I've also thought about setting off down a websockets library road, and (IIRC) I think Charles Warwick also was going there but there wasn't enough interest for him to pursue it.

But yes, I think what you've laid out here is reasonable. I believe bidirectional LC-JS communication is possible although I haven't had the need to test that out. And if that works then that's a valid publishable goal in itself. And working with JavaScript's callback/event loop mechanism would be the key.

I'd have more interest in this if there were a way to get websockets working on linux, where of course there's no LC browser but I haven't yet thought of a way to implement that.

bhall2001
Posts: 107
Joined: Thu Oct 30, 2014 3:54 pm
Location: Manchester, NH

Re: Websocket client Livecode

Post by bhall2001 » Tue Feb 14, 2023 6:05 pm

I've completed my proof of concept. It was pretty easy to get websockets going via javascript. To prove this out I created a very simple sample stack with the goal of sending a websocket message payload to LiveCode.

I have been able to do that to my satisfaction. I will be implementing this into one of my apps over the coming weeks. I'm sure there will be some hurdles I'll have to figure out but right now it's looking pretty good for what I will need to do.

I've attached my sample stack to this post. It's a very simple re-purpose of the websocket overview from javascript.info. It's a simple demonstration of opening a websocket, sending a message to the server and receiving a response. The connection is closed by the server 5 seconds after sending the response (note: this is not typical behavior of a websocket server but used for the demonstration to keep connections low).

Most of the magic is in the card script. It's not fancy but it does prove out the concept. I used LC v9.6.9 (rc2) when creating the stack.

Any questions of course reach out.

Bob
Attachments
Websocket POC.livecode.zip
(3.76 KiB) Downloaded 119 times

makeshyft
Posts: 220
Joined: Mon Apr 15, 2013 4:41 am
Contact:

Re: Websocket client Livecode

Post by makeshyft » Wed May 24, 2023 1:28 am

Thanks so much for sharing your proof of concept.
Did this implementation work well for you?
Founder & Developer @ MakeShyft R.D.A - https://www.makeshyft.com
Build Software with AppStarterStack for Livecode - https://www.AppStarterStack.com
Save Time with The Time Saver's Toolbox - https://www.TimeSaversToolbox.com

Post Reply

Return to “Internet”