visit
The idea is very simple:
The app has a simple HTTP server to send a message: GET xxx.xxx.xxx.1/?msg=message
GET xxx.xxx.xxx.2/?msg= message
...
GET xxx.xxx.xxx.254/?msg= message
We need to get the local IP address to send messages and to create an HttpServer instance. I created a simple method for this:
It returns an IP address something like this:
192.168.0.107
We will use the leading three octets to send a request to every local IP:
192.168.0.xxx
To able to receive requests we need to create an instance of
HttpServer
using our local IP and any port from 1024 to 65353.We return ‘Ok’ when we receive a request. To check if it works you can go to the link
//{your local IP}:8080
and you should see the ‘Ok’ message.Before checking on iOS or Android you need to add permissions.Add to iOS info.plist file:
<key>NSAppTransportSecurity</key>
<dict><key>NSAllowsArbitraryLoads</key><true/></dict>
Add to AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET" />
//{local IP}:8080?msg=message&ip=ip
If the request has the parameters like
and msg
we add those values to our message list and call the ip
setState
or notify to show that list on the screen:To get the full source, check the Github project below.In this example, it sends messages only to IP addresses from
x.x.x.1
to x.x.x.199
but theoretically, we can send it from 1 to 255.