title: websocket client discovering server
body: <p>I am in a situation where I want my websocket client to connect to server but server ip or dns name is unknown. Both client and server are in local network(connected to same router). I tried something like this....</p>
  
  <pre><code>var socket;
  for(var i=1; i&lt;255; i++) {
    socket = new WebSocket('ws://192.168.1.'+i+':8080/service');
  
    socket.onopen = function () {   
      console.log('WebSocket Connected!!');   
    };
  
    socket.onclose = function (event) {
      console.log('WebSocket Disconnected!!');
      socket.close();
    };
  
    socket.onmessage = function (event) {
      console.log('WebSocket receive msg: ' + event.data);
    }
  }
  </code></pre>
  
  <p>This works but I am not sure if I am doing it right or if there is a better way to do it. Any help is appreciated.</p>