收藏 分享(赏)

window8之保持网络连接-Maintaining network connectivity.docx

上传人:dreamzhangning 文档编号:2338245 上传时间:2018-09-11 格式:DOCX 页数:7 大小:38.71KB
下载 相关 举报
window8之保持网络连接-Maintaining network connectivity.docx_第1页
第1页 / 共7页
window8之保持网络连接-Maintaining network connectivity.docx_第2页
第2页 / 共7页
window8之保持网络连接-Maintaining network connectivity.docx_第3页
第3页 / 共7页
window8之保持网络连接-Maintaining network connectivity.docx_第4页
第4页 / 共7页
window8之保持网络连接-Maintaining network connectivity.docx_第5页
第5页 / 共7页
点击查看更多>>
资源描述

1、Maintaining network connectivity-保持网络连接原文地址:http:/ network connectivity-保持网络连接 .1作用 2In this section2快速开始:管理连接状态的改变 .3前提 3Summary 7Related topics /相关文章 7作用Use the Windows.Networking.Connectivity namespace provided in the Windows Runtime to enable your app to monitor and maintain the integrity of a c

2、onnected experience by registering for changes to network connection states or the data plan usage associated with a specific network connection.使用 WinRT 提供的 Windows.Networking.Connectivity 名字空间可以让你的应用程序通过注册网络连接的状态或者与一个特殊的网络连接关联的 data 的状态的监听器去监听和维护一段完整的连接。(注:网络连接的状态通常是指网络的是否连接,连接速度,协议信息等等;与一个特殊的网络连接

3、关联的 data 的状态:通过网络来对 data 作更新,我们不需要判断网络的状态,而只要判断 data 的状态就可以了,例如判断所需的 data 是否更新完毕。 )The topics in this section provide best practices and demonstrates how to register for these change notifications and respond to these events. For additional code examples, download the Network Information sample. For

4、 guidance specific to accessing the information for individual connections via connection profiles see, Accessing connection and data plan information.在这个章节中我们将提供最好的实例和演示如何为这些 change 通知注册监听器和对这些事件作出响应。更多的示例,你可以下载 Network Information sample。For guidance specific to accessing the information for indiv

5、idual connections via connection profiles see, Accessing connection and data plan information.In this sectionTopic DescriptionQuickstart: Managing connection state changesThis topic will show you how to register for connection state change event notifications and provides app behavior recommendation

6、s for enabling your app to use this information.Quickstart: Managing connections on metered networksThis topic details best practices for maintaining awareness of network connection cost or data plan status changes and enable your app to use this information to avoid incurring additional costs for r

7、oaming or exceeding a specified data transfer limit.快速开始:管理连接状态的改变原文地址:http:/ topic will show you how to register for connection state change event notifications and provides app behavior recommendations for enabling your app to use this information.本篇文章将会告诉你如何为连接状态的改变事件注册监听,并提供允许你的 app 使用这些信息的 app

8、的推荐行为。前提Knowing what a ConnectionProfile is and how to access the information that it represents is important; for more information see Quickstart: Retrieving network connection information. For additional code examples, download the Network Information sample.了解 ConnectionProfile 是什么和如何访问一些重要的信息。更多

9、的信息请看 Quickstart: Retrieving network connection information。其它的示例代码,请下载 Network Information sample。To ensure your Metro style app is network ready, you must set the capability in the projectPackage.appxmanifest file. For a definition of each network capability, see How to configure network isolation

10、 capabilities.确保你的 metro style app 的网络已经准备好了,你必须要在 projectPackage.appxmanifest文件中提前声明你的 app 需要用到网络。管理不同网络能力的描述,请看 How to configure network isolation capabilities.。What qualifies as a connection state change event?State change events indicate changes in the availability or type of connectivity offere

11、d by an individual connection. The NetworkConnectivityLevel enumeration defines possible state values.什么情况才能够判断说连接状态发生改变?状态改变的事件:当一个有效的改变或者网络提供商改变的时候。NetworkConnectivityLevel 列举了几种可能的连接状态的值。The latest connected apps frequently encounter network traversal scenarios typical of mobile device usage and

12、when Windows 8 Release Preview detects a new network, it will automatically provide it as a new connectivity option. For instance, if a user is using a device on a 3G/4G network to stream data, and later comes into range of a Wi-Fi network, the new connectivity option will be available for the appli

13、cation to leverage. Of course, this also means that a user can move out the range of a network, one that may even be in use.最近的链接上网络的 app 会频繁地遇到移动设备上的常见的网络遍历场景。和当Windows 8 Release Preview 发觉一个新的网络时,它会自动的将这个网络作为一个新的可选的链接项。举个例子,如果一个用户正在设备上使用 3G 或者 4G 的网络下载数据,稍后当它进入一个 wi-fi 网络的范围,那么这个 wi-fi 网络将会被加入新的链接

14、选项中。当然,居然有进入一个网络,那么也有当用户离开某个网络范围的时候,甚至这个网络是你正在使用的。Taking all of these possibilities into consideration, there is more than enough reason to equip your app with the logic that allows for smart choices when encountering changes to with network availability. Still, connections will not automatically sw

15、itch over to other connections seamlessly; your app needs to register for NetworkStatusChanged events and adapt accordingly.考虑到所有这些可能性,有足够的理由要求你的 app 在当可用网络改变的时候有智能选择的逻辑功能。任然,连接不应该被自动(随意)的切换到其它连接。你的 app 必须监听 NetworkStatusChanged 事件和做出相应的调整。Registering for notifications of connection state change eve

16、ntsBefore your app can adapt to changing network states it needs to know when they occur. The following code demonstrates registration for notification of NetworkStatusChange events for a specific connection profile.为连接的状态改变事件发出的通知注册在你的 app 对网络状态改变做出相应调整时,你必须知道这些网络状态是什么时候发生改变的。下面的代码演示一个特定的连接配置文件的网络状

17、态变化事件通知注册(伟大的 google) 。function RegisterForNetworkStatusChangeNotification() try if (!registeredNetworkStatusNotification) networkInfo.addEventListener(“networkstatuschanged“, OnNetworkStatusChange);registeredNetworkStatusNotification = true;if (internetProfileInfo = “) mySample.displayStatus(“No ne

18、twork status change. “);catch (e) mySample.displayError(“Exception Caught: “ + e + “nr“);Retrieving the connection state change informationNow when a status change occurs for the Internet connection profile, the following example function provides the associated ConnectionProfile.恢复连接状态信息现在当一个连接配置文件

19、的网络状态发生改变的时候,下面的示例函数提供了相关的连接配置文件。function OnNetworkStatusChange(sender) var internetProfileInfo = “;try internetProfileInfo = “Network Status Changed: nr“;var internetProfile = networkInfo.getInternetConnectionProfile();internetProfileInfo += GetConnectionProfileInfo(internetProfile) + “nr“;mySample

20、.displayStatus(internetProfileInfo);internetProfileInfo = “;catch (e) mySample.displayError(“Exception Caught: “ + e + “nr“);Recommended app behavior when handling connection state changesThe following steps represent the suggested connected app behavior while handling connection state changes:当网络连接

21、状态发生改变时推荐的 app 的行为下面是一些在网络连接状态改变事件的坚挺函数中推荐的一些步骤。Check for any costs associated with using the connection, and then adapt behavior as recommended in Quickstart: Managing connections on metered networks.1、 检查与连接相关的任何花销,然后根据 Quickstart: Managing connections on metered networks.中的建议调整行为(如进度条) 。Register

22、for network status change notifications.2、 监听网络状态改变的通知。A network status changed notification indicates that the available cost or connectivity options may have changed. When this notification is received do the following: Check the cost of connecting to the Internet. If the cost characteristic has c

23、hanged (free - cost, or cost - free), then retry the network operation. Windows Developer Preview will automatically use the best network/lowest cost network available. On retrying, if the network operation succeeds, then cancel the original network operation.Note Advanced developers may also choose

24、 to optimize app behavior when retrying network operations. For example, you may want to replace an existing connection with a new connection over a higher speed network. In this scenario, a developer can use the Sockets APIs, like StreamSocketInformation.BandwidthStatistics, to determine if switchi

25、ng to another connection is appropriate. If the cost characteristic of connecting to the Internet has not changed, but a cost-related notification is received, like 80% cap consumed, variable cost, roaming, and so on, then adapt behavior.3、 一个网络状态改变的通知表明现有成本或者连接选项已经发生改变。当收到这样的一个通知的时候做下面的这些事: 检查连接至互联

26、网的成本,如果成本的特性改变(免费-收费,或者从收费- 免费),接着重试网络的选项。Windows 开发人员预览将会自动使用最好的网络/最省钱的花费。Retrying 操作,如果操作成功,那么新网络将取代原先的网络连接。注意:高级的开发者可能也会选择去优化 app 的行为当重试一个新的网络的时候。举个例子,你可能想用新的高速的网络连接来代替一个已存在的连接。在这种情况下,开发者可以使用 Socket APIS。就像 StreamSocketInformation.BandwidthStatistics,来决定切换到另一个网络是否合理。 如果成本特征没有改变,但是 收到一个跟成本相关的通知,例如

27、,你已经使用了超过 80%流量,variable cost, roaming, and so on,那么调整行为。If the connection the app was using is no longer available (indicated by an error): Check the cost of connecting to the Internet. Retry the operation. If this fails, then wait for another NetworkStatusChanged event notification.Note The defaul

28、t policy in Windows 8 is to prefer an unrestricted network over a metered network and a faster network over a slower network.4、 如果你 app 正在使用的连接不在可使用: 检查联网费用 重试操作,如果失败,等待另一个 NetworkStatusChanged 通知。注意:Windows8 中的默认策略是一个不限量的网络限量的网络,一个更快的网络 慢速的网络。SummaryIn this topic, we reviewed how to register for co

29、nnection state change notifications and use these notifications to retrieve the ConnectionProfilefor which the event occurred. We also reviewed basic connected app behavior when dealing with these state changes.While this covers the basic network availability scenario, a NetworkStatusChanged event c

30、an also represent a change to the connection cost and data plan properties of a ConnectionProfile. For more information and guidance on how best to engage these scenarios, see Quickstart: Managing connections on metered networks.概要本章中,我们复习如何为连接状态发生改变通知注册监听和使用这些通知来恢复引发这个事件的连接配置。我们也复习当处理这些状态改变事件时基本连接

31、app 的行为.虽然这个也覆盖到了基本网络可用性的章节。NetworkStatusChanged 事件也代表了连接成本和数据 ConnectionProfile 文件的计划属性的变化. For more information and guidance on how best to engage these scenarios, see Quickstart: Managing connections on metered networksRelated topics /相关文章Network Information sampleQuickstart: Retrieving network connection informationQuickstart: Managing connections on metered networksWindows.Networking.Connectivity

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报