• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# NetworkReachability类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中NetworkReachability的典型用法代码示例。如果您正苦于以下问题:C# NetworkReachability类的具体用法?C# NetworkReachability怎么用?C# NetworkReachability使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NetworkReachability类属于命名空间,在下文中一共展示了NetworkReachability类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Reachability

 /// <summary>
 /// Initializes a new instance of the <see cref="Reachability.Reachability"/> class.
 /// </summary>
 /// <param name='reachability'>
 /// NetworkReachability instance to use
 /// </param>
 /// <param name='hasWWAN'>
 /// Platform has a WWAN interface
 /// </param>
 protected Reachability(NetworkReachability reachability, bool hasWWAN)
 {
     NetworkReachability = reachability;
     HasWWAN = hasWWAN;
     AllowWWAN = true;
     NetworkReachability.SetNotification(OnReachabilityNotification);
     NetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
 }
开发者ID:pavlob0910,项目名称:my-start-stable,代码行数:17,代码来源:Reachability.cs


示例2: NetworkInformation

        static NetworkInformation()
        {
#if __ANDROID__
            _manager = ConnectivityManager.FromContext(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity);
            //_manager = ConnectivityManager.FromContext(InTheHand.Platform.Android.ContextManager.Context);
#elif __IOS__ || __TVOS__
            _reachability = new NetworkReachability("0.0.0.0");
#endif
        }
开发者ID:inthehand,项目名称:Charming,代码行数:9,代码来源:NetworkInformation.cs


示例3: IsNetworkAvailable

		static bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
		{
			if (defaultRouteReachability == null) {
				defaultRouteReachability = new NetworkReachability(new IPAddress(0));
				defaultRouteReachability.SetNotification(OnChange);
				defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
			}
			return defaultRouteReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags);
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:9,代码来源:reachability.cs


示例4: ConvertDataType

 public static ENetworkDataType ConvertDataType(NetworkReachability type)
 {
     //return ENetworkDataType.MobileData;
     return type == NetworkReachability.NotReachable ?
         ENetworkDataType.None :
         type == NetworkReachability.ReachableViaCarrierDataNetwork ?
         ENetworkDataType.MobileData :
         ENetworkDataType.Cable;
 }
开发者ID:npnf-seta,项目名称:Fox-Poker,代码行数:9,代码来源:Utility.cs


示例5: IsAdHocWiFiNetworkAvailable

		public static bool IsAdHocWiFiNetworkAvailable (out NetworkReachabilityFlags flags)
		{
			if (adHocWiFiNetworkReachability == null) {
				adHocWiFiNetworkReachability = new NetworkReachability(new IPAddress(new byte [] { 169, 254, 0, 0 }));
				adHocWiFiNetworkReachability.SetNotification(OnChange);
				adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
			}

			return adHocWiFiNetworkReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags);
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:10,代码来源:reachability.cs


示例6: IsHostReachable

		// Is the host reachable with the current network configuration
		public static bool IsHostReachable(string host)
		{
			if (string.IsNullOrEmpty(host))
				return false;

			using (var r = new NetworkReachability(host)) {
				NetworkReachabilityFlags flags;

				if (r.TryGetFlags(out flags))
					return IsReachableWithoutRequiringConnection(flags);
			}
			return false;
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:14,代码来源:reachability.cs


示例7: IsAdHocWiFiNetworkAvailable

    //
    // Returns true if it is possible to reach the AdHoc WiFi network
    // and optionally provides extra network reachability flags as the
    // out parameter
    //
    public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags)
    {
        if (_adHocWiFiNetworkReachability == null) {
            _adHocWiFiNetworkReachability = new NetworkReachability (new IPAddress (new byte[] { 169, 254, 0, 0 }));
            _adHocWiFiNetworkReachability.SetCallback (OnChange);
            _adHocWiFiNetworkReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
        }

        if (!_adHocWiFiNetworkReachability.TryGetFlags (out flags))
            return false;

        return IsReachableWithoutRequiringConnection (flags);
    }
开发者ID:harryxiaxia,项目名称:ibeaconDemo,代码行数:18,代码来源:Reachability.cs


示例8: InitializeReachability

		void InitializeReachability ()
		{
			networkReachability = new NetworkReachability (IPAddress.Any);
			networkReachability.SetNotification (flags => UpdateReachability (flags, NetworkIcon, NetworkStatusTextField));
			networkReachability.Schedule ();

			NetworkReachabilityFlags networkReachabilityFlags;
			networkReachability.TryGetFlags (out networkReachabilityFlags);
			UpdateReachability (networkReachabilityFlags, NetworkIcon, NetworkStatusTextField);

			CreateHostReachability ();

			HostTextField.Changed += (sender, e) => CreateHostReachability ();
		}
开发者ID:RafasTavares,项目名称:mac-samples,代码行数:14,代码来源:MainWindowController.cs


示例9: IsHostReachable

		// Is the host reachable with the current network configuration
		public static bool IsHostReachable (string host)
		{
			if (host == null || host.Length == 0)
				return false;
	
			using (var r = new NetworkReachability (host)){
				NetworkReachabilityFlags flags;
	
				if (r.TryGetFlags (out flags)){
					return IsReachableWithoutRequiringConnection (flags);
				}
			}
			return false;
		}
开发者ID:oduma,项目名称:Sciendo.Fitas.Droid,代码行数:15,代码来源:Reachability.cs


示例10: IsAdHocWiFiNetworkAvailable

        public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags)
        {
            if (adHocWiFiNetworkReachability == null)
            {
                adHocWiFiNetworkReachability = new NetworkReachability(new IPAddress(new byte[] {169, 254, 0, 0}));
#warning Need to look at SetNotification instead - ios6 change
                adHocWiFiNetworkReachability.SetNotification(OnChange);
                adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }

            if (!adHocWiFiNetworkReachability.TryGetFlags(out flags))
                return false;

            return IsReachableWithoutRequiringConnection(flags);
        }
开发者ID:Everbridge,项目名称:sm-MvvmCross,代码行数:15,代码来源:MvxReachability.cs


示例11: FinishedLaunching

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        imageCarrier = UIImage.FromFile ("WWAN5.png");
        imageWiFi = UIImage.FromFile ("Airport.png");
        imageStop = UIImage.FromFile ("stop-32.png");

        nr = new NetworkReachability ("www.apple.com");
        nr.SetCallback (ReachabilityChanged);
        nr.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);

        AddTable ();
        //UpdateStatus ();
        //UpdateCarrierWarning ();

        window.MakeKeyAndVisible ();

        return true;
    }
开发者ID:CVertex,项目名称:monotouch-samples,代码行数:18,代码来源:main.cs


示例12: IsHostReachable

		/// <summary>
		/// Checks if host is reachable
		/// </summary>
		/// <param name="host"></param>
		/// <param name="port"></param>
		/// <returns></returns>
		public static bool IsHostReachable (string host, int port)
		{
			if (string.IsNullOrWhiteSpace (host))
				return false;

			IPAddress address;
			if (!IPAddress.TryParse (host + ":" + port, out address)) {
				Debug.WriteLine (host + ":" + port + " is not valid");
				return false;
			}
			using (var r = new NetworkReachability (host)) {

				NetworkReachabilityFlags flags;

				if (r.TryGetFlags (out flags)) {
					return IsReachableWithoutRequiringConnection (flags);
				}
			}
			return false;
		}
开发者ID:NateRickard,项目名称:Xamarin.Plugins,代码行数:26,代码来源:Reachability.cs


示例13: CreateHostReachability

		void CreateHostReachability ()
		{
			if (hostReachability != null) {
				hostReachability.Unschedule ();
				hostReachability.Dispose ();
			}

			if (String.IsNullOrEmpty (HostTextField.StringValue)) {
				HostIcon.Image = NSImage.ImageNamed ("disconnected");
				HostStatusTextField.StringValue = "Enter a host name or IP address";
				return;
			}

			hostReachability = new NetworkReachability (HostTextField.StringValue);
			hostReachability.SetNotification (flags => UpdateReachability (flags, HostIcon, HostStatusTextField));
			hostReachability.Schedule ();

			NetworkReachabilityFlags networkReachabilityFlags;
			networkReachability.TryGetFlags (out networkReachabilityFlags);
			UpdateReachability (networkReachabilityFlags, NetworkIcon, NetworkStatusTextField);
		}
开发者ID:RafasTavares,项目名称:mac-samples,代码行数:21,代码来源:MainWindowController.cs


示例14: CreateConnectivityWatchDog

		public void CreateConnectivityWatchDog (Action<bool> connectivityChanged)
		{
			this.connectivityChanged = connectivityChanged;

			if (remoteHostReachability == null)
			{
				if (remoteHostReachability != null)
				{
					remoteHostReachability.Unschedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
				}

				// Create new instance if host address changed.
				remoteHostReachability = new NetworkReachability(new System.Net.IPAddress(0));
				remoteHostReachability.SetNotification(HandleReachabilityChanged);
				remoteHostReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
			}

			// Trigger callback.
			if (this.connectivityChanged != null)
			{
				this.connectivityChanged (true);
			}
		}
开发者ID:flolovebit,项目名称:xamarin-evolve-2014,代码行数:23,代码来源:AppleConnectivityServiceImpl.cs


示例15: IsNetworkAvailable

        static bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
        {

            if (defaultRouteReachability == null)
            {
                var data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 0 };
                var ip = new IPAddress(data, 0);
                defaultRouteReachability = new NetworkReachability(ip);
                defaultRouteReachability.SetNotification(OnChange);
                defaultRouteReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);
            }
            if (!defaultRouteReachability.TryGetFlags(out flags))
                return false;
            return IsReachableWithoutRequiringConnection(flags);
        }
开发者ID:charifield,项目名称:Xamarin.Plugins,代码行数:15,代码来源:Reachability.cs


示例16: IsHostReachable

        // Is the host reachable with the current network configuration
        public static bool IsHostReachable(string host)
        {
            if (host == null || host.Length == 0)
             return false;

            #if WINDOWS_PHONE
             //I know I know, but I'm trying to keep the behavior the same across platforms
             bool done = false;
             bool reachable = false;
             DeviceNetworkInformation.ResolveHostNameAsync(new DnsEndPoint(HostName, 80), (x) => {
             done = true;
             if (x.NetworkErrorCode == NetworkError.Success)
             reachable = true;
             else
             reachable = false;
             }, null);

             while (!done) { Thread.Sleep(200); }

             return reachable;

            #elif IPHONE

             using (var r = new NetworkReachability (host)){
             NetworkReachabilityFlags flags;

             if (r.TryGetFlags (out flags)){
             return IsReachableWithoutRequiringConnection (flags);
             }
             }
             return false;
            #else
             var test = new Ping();
             var reply = test.Send(HostName);

             if (reply.Status == IPStatus.Success)
             return true;
             else
             return false;
            #endif
        }
开发者ID:n1ckd0r,项目名称:mogade-csharp,代码行数:42,代码来源:Reachability.cs


示例17: IsNetworkAvaialable

        private static bool IsNetworkAvaialable(out NetworkReachabilityFlags flags)
        {
            if (defaultRouteReachability == null)
            {
                defaultRouteReachability = new NetworkReachability(new IPAddress(0));
#warning Need to look at SetNotification instead - ios6 change
                defaultRouteReachability.SetNotification(OnChange);
                defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }
            if (defaultRouteReachability.TryGetFlags(out flags))
                return false;
            return IsReachableWithoutRequiringConnection(flags);
        }
开发者ID:Everbridge,项目名称:sm-MvvmCross,代码行数:13,代码来源:MvxReachability.cs


示例18: IsNetworkAvaialable

        /// <summary>
        /// 
        /// </summary>
        /// <param name="flags">
        /// A <see cref="NetworkReachabilityFlags"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        private static bool IsNetworkAvaialable(out NetworkReachabilityFlags flags)
        {
            NetworkReachability defaultRouteReachability = new NetworkReachability (new IPAddress (0));

            if (defaultRouteReachability.TryGetFlags (out flags))
                return false;
            return IsReachable (flags) && IsNoConnectionRequired(flags);  // is reachable without requiring connection.
        }
开发者ID:jioe,项目名称:appverse-mobile,代码行数:17,代码来源:IPhoneNet.cs


示例19: RemoteHostStatus

        /// <summary>
        /// 
        /// </summary>
        /// <param name="host">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="NetworkType"/>
        /// </returns>
        private static NetworkType RemoteHostStatus(string host)
        {
            bool reachable = IsHostReachable(host);;

            if (!reachable)
                return NetworkType.Unknown;

            using (var r = new NetworkReachability (host)){
                NetworkReachabilityFlags flags;

                if (r.TryGetFlags (out flags)){
                    if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
                        //return NetworkType.Carrier_GSM;  // TODO get which type of carrier is being used.
                        return NetworkType.Carrier_3G; // HARDCODED.
                }
            }

            return NetworkType.Wifi;
        }
开发者ID:jioe,项目名称:appverse-mobile,代码行数:28,代码来源:IPhoneNet.cs


示例20: IsAdHocWiFiNetworkAvailable

        /// <summary>
        /// 
        /// </summary>
        /// <param name="flags">
        /// A <see cref="NetworkReachabilityFlags"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        private static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags)
        {
            NetworkReachability adHocWiFiNetworkReachability = new NetworkReachability (new IPAddress (new byte [] {169,254,0,0}));

            if (!adHocWiFiNetworkReachability.TryGetFlags (out flags))
                return false;

            return IsReachable (flags) && IsNoConnectionRequired(flags);  // is reachable without requiring connection.
        }
开发者ID:jioe,项目名称:appverse-mobile,代码行数:18,代码来源:IPhoneNet.cs



注:本文中的NetworkReachability类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# NetworkReachabilityFlags类代码示例发布时间:2022-05-24
下一篇:
C# NetworkPlayer类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap