- 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