@ Override public void initialize ( ) throws XMPPException { LOGGER . fine ( "Initialized" ) ; if ( ! isResolving ( ) && ! isResolved ( ) ) { // Get the best STUN server available if ( currentServer . isNull ( ) ) { loadSTUNServers ( ) ; } // We should have a valid STUN server by now... if ( ! currentServer . isNull ( ) ) { clearCandidates ( ) ; resolverThread = new Thread ( new Runnable ( ) { @ Override public void run ( ) { // Iterate through the list of interfaces, and ask // to the STUN server for our address. try { Enumeration < NetworkInterface > ifaces = NetworkInterface . getNetworkInterfaces ( ) ; String candAddress ; int candPort ; while ( ifaces . hasMoreElements ( ) ) { NetworkInterface iface = ifaces . nextElement ( ) ; Enumeration < InetAddress > iaddresses = iface . getInetAddresses ( ) ; while ( iaddresses . hasMoreElements ( ) ) { InetAddress iaddress = iaddresses . nextElement ( ) ; if ( ! iaddress . isLoopbackAddress ( ) && ! iaddress . isLinkLocalAddress ( ) ) { // Reset the candidate candAddress = null ; candPort = - 1 ; DiscoveryTest test = new DiscoveryTest ( iaddress , currentServer . getHostname ( ) , currentServer . getPort ( ) ) ; try { // Run the tests and get the // discovery // information, where all the // info is stored... DiscoveryInfo di = test . test ( ) ; candAddress = di . getPublicIP ( ) != null ? di . getPublicIP ( ) . getHostAddress ( ) : null ; // Get a valid port if ( defaultPort == 0 ) { candPort = getFreePort ( ) ; } else { candPort = defaultPort ; } // If we have a valid candidate, // add it to the list. if ( candAddress != null && candPort >= 0 ) { TransportCandidate candidate = new TransportCandidate . Fixed ( candAddress , candPort ) ; candidate . setLocalIp ( iaddress . getHostAddress ( ) != null ? iaddress . getHostAddress ( ) : iaddress . getHostName ( ) ) ; addCandidate ( candidate ) ; resolvedPublicIP = candidate . getIp ( ) ; resolvedLocalIP = candidate . getLocalIp ( ) ; return ; } } catch ( Exception e ) { LOGGER . log ( Level . SEVERE , "Exception" , e ) ; } } } } } catch ( SocketException e ) { LOGGER . log ( Level . SEVERE , "Exception" , e ) ; } finally { setInitialized ( ) ; } } } , "Waiting for all the transport candidates checks..." ) ; resolverThread . setName ( "STUN resolver" ) ; resolverThread . start ( ) ; } else { throw new IllegalStateException ( "No valid STUN server found." ) ; } } }
Initialize the resolver .