Thanks, Alex. I may need something more refined later on, but for now my modest needs appear to be well met through simple brute force:

At the moment this is for some network tools for students to use in a classroom. Ideally there would be no Internet connection, just a local network of a small number of devices all using a single wifi router.

I had experimented briefly with a UDP broadcast, but ran into an issue in which it seemed the server wasn't receiving the message.

Before spending more time on that I tried a different tack with TCP.

With Bob's IPCalc function I'm able to get the first and last addresses of the local subnet. His function needs the local IP and subnet mask, which can be obtained on Mac and Linux with a shell call to ifconfig, and on Win with ipconfig.

Armed with that I just attempt a TCP connection to each device in turn, looking for a specific reply. When I get what I expect, I know I've reached my app on the other machine. Takes less than a second to scan the network.

Done in a few minutes' work.

Of course this won't do much for mobile devices (how do I get the local address on iOS and Android without shell?), but since UDP is off the table there anyway I'm no worse off, and can at least get started with laptops and Raspberry Pis happily talking to one another...

--
 Richard Gaskin
 Fourth World Systems


Alex Tweedly wrote:

it might help if you were to more precisely describe the problem you are
seeking to solve.

If you need to discover all/any/arbitrary listeners - then "what Bob said".

If you need to discover listeners for a specific port/service provided
by some other apps/servers in a standard way - then "what Monte said".

If you need to discover instances of "your own" server on the LAN, then
there may be an other solution..... depending on how well defined "my
LAN" is.

Basically,

- every server listens for UDP packet on some port

  - client sends a broadcast UDP request to that port

  - servers respond.

This assumes that you can *reliably* depend on your LAN being a single
subnet, that your LAN is not too huge :-), that all servers are within
your control and you can add such a listener to them, etc.

NB - this is only a solution for desktops (only they can send broadcasts).

For ios you can use mergSomething :-)

For Android, afaik there isn't anything to allow broadcast transmission,
so I think your only solution for now is to move to a
broadcast/advertisement approach - servers (currently desktop only, you
said) must advertise their service, and Android clients can listen for
such adverts and thus learn where the service is available. This is only
feasible if you know of limits on the number of servers & services - or
(for-android as-client) if you are willing to add significant complexity
and have proxy-servers handle it for you; you can do that in an
automatic way (i.e. no configuration needed) but it is complex.

Don't even start down that road unless you need this for Android before
the timeframe for either bonjour or sockets on android.

(But if you do want to go down that road, get in touch I'd be happy to
collaborate)

-- Alex.


On 27/10/2016 22:12, Richard Gaskin wrote:
I'd like to have an app automatically discover and attempt connection
to other devices on my LAN.

Looking through the list archives I can find a few half-solutions, but
not one which works well across the platforms LC supports (Mac, Win,
Linux, iOS, Android).

At this time the only things listening on a port will be desktop
computers, but I still need to be able to connect with them from any
other device on the local network, and down the road I may want to
allow even handheld devices to take on an accept role.

Any robust, tested solutions available?



_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to