LC App to App Communication

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.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

LC App to App Communication

Post by simon.schvartzman » Mon Jun 12, 2017 7:52 pm

Hi geeks, I'm looking for inspiration about the simplest way to accomplish the following:

1 - There will be one (the same) LC developed application running on two mobiles (lets call them M1 & M2).
2 - At any given time M1 (at user request) should be able to send a command to M2 for it to execute something. M1 will stay put wait for a response.
3 - Once M2 performs its task it should answer to M1 by sending a file.
4 - Both devices will have internet connectivity and initially will be very close to each other (meaning bluetooth communication is a possibility).

Any ideas? If there is an example or tutorial with something similar it will be of great help.

Many thanks ...
Simon
________________________________________
To ";" or not to ";" that is the question

matthiasr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 190
Joined: Sat Apr 08, 2006 7:55 am
Location: Lübbecke, Germany
Contact:

Re: LC App to App Communication

Post by matthiasr » Mon Jun 12, 2017 9:15 pm

Simon,

Bjoernke von Gierke created a chat program ChatRev some time ago. He´s also offering the sources for the client and the server. Maybe this is useful for you

http://bjoernke.com/?target=chatrev

Regards,

Matthias

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

Re: LC App to App Communication

Post by FourthWorld » Mon Jun 12, 2017 10:14 pm

There's also a chat client and server example included in the LiveCode installation - click "Resources" in the LC toolbar, then in the Resource Center window click "Sample Projects", and the first is "Internet Chat".

Of all the client-server tutorials I've seen, I like this one best:
http://lessons.livecode.com/m/4071/l/12 ... ng-sockets

I should note that all of these are client-server, and it sounds like what you'd ideally like is peer-to-peer. It's possible to do some forms of P2P in LC, esp. with some of the newer extensions to LC's socket handling. But P2P is notoriously complicated to work out on some networks, which is why many P2P systems offer client-server as a fallback. Depending on the specifics of your app, you may find client-server simpler to set up than a robust P2P that can stand up to the various network blocks you may find.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 755
Joined: Fri Jun 27, 2008 9:00 pm

Re: LC App to App Communication

Post by Mikey » Tue Jun 13, 2017 2:56 pm

If the chat option isn't reasonable, then here's a quick and dirty and cheap solution that I've used several times:
1. Use a file sharing service. You can use Box, Dropbox, Google Drive, or others. For this example, I am suggesting Dropbox, because we have a good API from LiveCode,
2. Each device updates a file (or folder) on the server using the LC Dropbox library.
3. On a desktop machine, have the Dropbox app running. That will sync the Dropbox folder with the Dropbox server.
4. LC on the desktop checks the Dropbox folder for updates. If there's an update, LC on the desktop sends a push notification to the other device with the contents of the message.

The advantage of this approach is that the user doesn't have to have the app running and in focus.

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: LC App to App Communication

Post by simon.schvartzman » Tue Jun 13, 2017 10:51 pm

Thank you all for your useful ideas.

As @FourthWorld suggested my ideal solution would be a P2P communication by if it is too complicated I guess a Client / Server approach will be enough. I will try it.

@Mikey idea is a good one but I would prefer to avoid using a desktop.

Thanks again to all for answering.
Simon
________________________________________
To ";" or not to ";" that is the question

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: LC App to App Communication

Post by simon.schvartzman » Tue Jun 20, 2017 9:51 pm

@FourthWorld I have followed I have downloaded the Internet Chat included in the Resource Center and it works like a charm with a localHost but I can't make it work when the server is not local.

Just to make it clear (I was not clear enough on the original post) what I want to accomplish is the following:

I have two mobiles connected to the internet via 3G/4G and I would like one to be acting as the Server and the other as the Client.

I check the Server IP address using www.iplocation.net, then I manually input that IP address on the Client application but the connection is never established.

Not sure if I'm doing something wrong or if what I want to do is not possible.

Looking forward for help!

Thanks
Simon
________________________________________
To ";" or not to ";" that is the question

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

Re: LC App to App Communication

Post by FourthWorld » Tue Jun 20, 2017 11:01 pm

P2P si tricky because good security practice prevents systems from opening sockets without admin privileges. On mobile devices the means to do this will vary, if supported at all. Wifi router firewalls may also prevent devices from accepting connections as well, requiring that they be configured with port forwarding, not usually something we want to require home users to deal with, and may be completely forbidden in well run business networks.

So what I was proposing was to consider client-server rather than P2P, in which both devices relay messages to each other through a common external server. That way only the server is listening to a port, while the other two initiate the connection as outbound only, which (depending on port number used) usually allowed by most networks.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Talking LiveCode”