title: Javascript function to find out client ip calls java before it assigns the value
body: <p>This is the example I am trying : 
  <a href="https://ourcodeworld.com/articles/read/257/how-to-get-the-client-ip-address-with-javascript-only" rel="nofollow noreferrer">https://ourcodeworld.com/articles/read/257/how-to-get-the-client-ip-address-with-javascript-only</a></p>
  
  <p>This is the fiddle:
  <a href="https://jsfiddle.net/ourcodeworld/cks0v68q/?utm_source=website&amp;utm_medium=embed&amp;utm_campaign=cks0v68q" rel="nofollow noreferrer">https://jsfiddle.net/ourcodeworld/cks0v68q/?utm_source=website&amp;utm_medium=embed&amp;utm_campaign=cks0v68q</a></p>
  
  <pre><code> /**
   * Get the user IP throught the webkitRTCPeerConnection
   * @param onNewIP {Function} listener function to expose the IP locally
   * @return undefined
   */
  function getUserIP(onNewIP) { //  onNewIp - your listener function for new IPs
      //compatibility for firefox and chrome
      var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
      var pc = new myPeerConnection({
          iceServers: []
      }),
      noop = function() {},
      localIPs = {},
      ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g,
      key;
  
      function iterateIP(ip) {
          if (!localIPs[ip]) onNewIP(ip);
          localIPs[ip] = true;
      }
  
       //create a bogus data channel
      pc.createDataChannel("");
  
      // create offer and set local description
      pc.createOffer(function(sdp) {
          sdp.sdp.split('\n').forEach(function(line) {
              if (line.indexOf('candidate') &lt; 0) return;
              line.match(ipRegex).forEach(iterateIP);
          });
  
          pc.setLocalDescription(sdp, noop, noop);
      }, noop); 
  
      //listen for candidate events
      pc.onicecandidate = function(ice) {
          if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;
          ice.candidate.candidate.match(ipRegex).forEach(iterateIP);
      };
  }
  
  // Usage
  
  getUserIP(function(ip){
          document.getElementById("ip").innerHTML = 'Got your IP ! : '  + ip + " | verify in http://www.whatismypublicip.com/";
  });
  </code></pre>
  
  <p>Problem I am facing: This example is working fine for on load case. But when I am calling this function on button click, the ip is getting assigned after the control exits from the Javascript call and hits the Java end. Tested in Firefox and Chrome.</p>
  
  <p>I am not literate enough to understand the Javascript. Can someone help to find out what is the problem?</p>