Discover hotspot IP number

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Discover hotspot IP number

Post by trevix » Sun Jan 02, 2022 10:17 pm

Imagine this situation:
- I have an Android device A in a room,running a WiFi hotspot (no connection to internet) and a Livecode App in it that acts as a server, accepting connections on a pre-defined port.
- The device is shut down every evening and restarted every morning: so the hotspot function gets restarted and changes the IP number every day.

A second device B (Android or iOS) is brought in the room and the user manually connect to the hotspot wifi of A. B has a LC App that is able to open a socked to the App running on A

How can App B find out the needed IP number of A?

I need some hint on how to create this thing (if possible).
Note: I would like the connection to be established without having to show on A and type on B the IP, or using QRcode or else. Just enter the room, connect to wifi, click on a button on B and the App find the server and connect.

I tried to run some loops on "open socket" but things get confused very fast, trying to avoid his own IP, other eventual WiFi networks, socket errors, etc.
See below:

Code: Select all

....
   --run the search
     -- 254 is my router
     repeat with U = 1 to 253
          put "192.168.1." & U into tServer 
          if tServer = sMyIP then next repeat --don't call myself
          if sSocket is empty then
               open socket to tServer & ":" & kPort with message "broadcastClientConnected"
               if  the result is empty then
                    put the long time && "In connessione" & cr  into fld "FldLog" 
                    set the label of btn "BtnConnect" to "Disconnetti"
               else
                    put 1 && "Non apro il socket: " && the result into fld "FldLog"
                    broadcastClientStop
               end if
          end if
          if sSocket is not empty then 
               exit repeat
          end if
     end repeat
---

Code: Select all

on broadcastClientConnected pSocket
set the label of btn "BtnConnect" to "Disconnect"
     read from socket pSocket until return with message "broadcaseClientMessageReceived"
     if the result is empty then
          put pSocket into sSocket
          put kEmail into TheEmail --the email is the identifier
          put CodificaDati(TheEmail) into TheEmail
          put the number of chars of TheEmail into TheLenght
          broadcastClientSend "AUTH" & comma & TheLenght  & return & TheEmail 
          --close sockets witout answer 
          repeat for each line TheSocket in the OpenSockets
               if ":" is in TheSocket AND TheSocket <> sSocket then --don't close the socket of the server if in the same pc
                    close socket TheSocket
               end if
          end repeat
     else
          DoTheLog "Connection problems" && the result
          set the label of btn "BtnConnect" to "Connect"
     end if
end broadcastClientConnected
Thanks
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Discover hotspot IP number

Post by mrcoollion » Mon Jan 03, 2022 8:57 am

Just an idea.

You could try to do a tracert command in a shell command. The TRACERT diagnostic command determines the RouTe to a destination IP address.
E.g put shell("tracert <any existing IP address in the home>") should give a list of IP addresses the device is connected to. The first one should be the hotspot it is connected to.

I forgot: Shell does not work on mobile devices... :(

Regards,

Paul

trevix
Posts: 960
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Discover hotspot IP number

Post by trevix » Wed Oct 11, 2023 8:41 am

Hello.
Can you clarify or give some hints on how to apply the Multicast DNS on mobile with Livecode?
One similar approach would be, on app launch, that every device communicate its IP to our web server, linked to a common registration.
So, more or less, the client could retrieve the server IP and then open a socket to it.
But, given the difficulties on distinguishing the returns of Networkinterfaces (wifi, ethernet, hotspot, remote debugger, data cell, etc) I see this quite difficult to implement.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

Post Reply

Return to “Internet”