public async Task <P2PConnectionImpl> Run() { try { m_Socket = new UdpSocket(); m_Socket.Bind(); var stunResult = await StunClient.Run(m_Socket.m_UdpClient, m_StunURL, 19302, m_Token); var response = await m_Func(stunResult, m_Token); m_Token.ThrowIfCancellationRequested(); return(new P2PConnectionImpl(response, m_Socket)); } catch (Exception ex) { Log.Exception(ex); m_Socket.Dispose(); throw; } }
/// <summary> /// Retrieves an enumerable collection of th XMPP client's external IP /// addresses. /// </summary> /// <returns>An enumerable collection of the XMPP client's external IP /// addresses.</returns> /// <exception cref="NotSupportedException">The external IP address(es) /// could not be determined.</exception> /// <remarks>In simple configurations this should usually yield one external /// IP address only.</remarks> IEnumerable <IPAddress> GetExternalAddresses() { // Use a set so we don't get duplicate addresses. ISet <IPAddress> set = new HashSet <IPAddress>(); try { set.Add(serverIpCheck.GetExternalAddress()); } catch { // Fall through if server does not support the 'Server IP Check' extension. } // Next, try to retrieve external IP addresses from UPnP-enabled devices. if (UseUPnP) { #if WINDOWSPLATFORM try { foreach (var address in UPnP.GetExternalAddresses()) { set.Add(address); } } catch (Exception) { // Fall through in case any device querying goes wrong. } #endif } // Finally, perform a STUN query. try { set.Add(StunClient.Query(StunServer.Host, StunServer.Port, 3000)); } catch { // Nothing to do here. } // See if we could gather any external addresses at all. if (set.Count == 0) { throw new NotSupportedException("The external IP address(es) could not " + "be obtained."); } return(set); }
private IEnumerable <IPAddress> GetExternalAddresses() { ISet <IPAddress> set = new HashSet <IPAddress>(); try { set.Add(this.serverIpCheck.GetExternalAddress()); } catch { } if (this.UseUPnP) { try { foreach (IPAddress address in UPnP.GetExternalAddresses()) { set.Add(address); } } catch (Exception) { } } try { set.Add(StunClient.Query(this.StunServer.Host, this.StunServer.Port, 0xbb8)); } catch { } if (set.Count == 0) { throw new NotSupportedException("The external IP address(es) could not be obtained."); } return(set); }