I have a web application runing in a front-end web that connects through tcp WebSocket protocol to an Android device in the same local network through WiFi.
Right now, the Android device sets up a WebSocket server (since most web browsers do not support WebSocket server creation it the Device who acts as server) and I manually insert the device IP on the web application and press a "connect" button to start the communication.
I would like to perform this connection automatically by making the web application to search for websocket servers in its local area network. How can this be done? Would a brute force approach by trying to connect to all possible IPs iteratively work? Is there some other efficient approach?
Thank you.
An iterative approach would work if the subnet is small, most home routers have small subnets ... However on a more complicated network, an iterative approach would not be feasible, you'd need to use a service discovery protocol like mdns or ssdp. However, these are probably not available to a web browser, your best bet as an alternative would be a server sitting on the internet where the devices could rendezvous and exchange local IP information... However, if the network is sufficiently complicated, even devices with the same external IP might not be able to communicate between their respective subnets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With