Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service discovery in local network using WebSockets

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.

like image 226
Alex Avatar asked Jul 29 '15 09:07

Alex


1 Answers

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.

like image 109
silverjam Avatar answered Oct 30 '22 07:10

silverjam