private static IPEndPoint BindToEndPoint(Socket socket) { IPEndPoint bindEndPoint = null; UdpCacheClientSettings settings = UdpCacheClientSettings.GetConfig(); int[] ports = settings.GetPorts(); for (int i = 0; i < ports.Length; i++) { try { bindEndPoint = new IPEndPoint(settings.Address, ports[i]); socket.Bind(bindEndPoint); socket.ReceiveTimeout = 1000; break; } catch (SocketException ex) { if (ex.SocketErrorCode != SocketError.AddressAlreadyInUse) { throw; } } } ExceptionHelper.FalseThrow(socket.IsBound, "Cache监听线程不能找到可以监听的端口"); return(bindEndPoint); }
/// <summary> /// 获取udpCacheNotifierSettings的配置信息 /// </summary> /// <returns>UdpCacheNotifierSettings实例</returns> public static UdpCacheClientSettings GetConfig() { UdpCacheClientSettings result = (UdpCacheClientSettings)ConfigurationBroker.GetSection("udpCacheClientSettings"); if (result == null) result = new UdpCacheClientSettings(); return result; }
/// <summary> /// 获取udpCacheNotifierSettings的配置信息 /// </summary> /// <returns>UdpCacheNotifierSettings实例</returns> public static UdpCacheClientSettings GetConfig() { UdpCacheClientSettings result = (UdpCacheClientSettings)ConfigurationBroker.GetSection("udpCacheClientSettings"); if (result == null) { result = new UdpCacheClientSettings(); } return(result); }