Network Awareness


Although applications have had to interact with the network for many years , few have done a good job of staying aware of the network and dynamically changing their behavior to best suit current conditions. For example, todays smart client applications are considered advanced if they simply support an online/offline mode. While being aware of online/offline status is an important part of unity with the network, applications can do much more. For example, an application that is aware of network characteristics, such as connection speed and throughput between local and remote endpoints, can provide a much richer experience than an application that simply goes offline when the network is slow. Imagine an application that is written in such a way that it works with minimal reliance on the network in low bandwidth conditions, but automatically senses increases in speed and throughput and reacts accordingly to improve the user experience. Whats more, this application could use network fingerprinting techniques to recognize different network configurations and remember which services were available the last time it ran on them or even associate a geographical location with that network.

Developers building .NET applications should be aware of the potential for network awareness and plan for it in an application. For example, you should consider factoring protocol logic and business logic into the application in such a way that the network intensive protocols can be used in high bandwidth cases, but the application can have a fallback in lower bandwidth scenarios. If your application is rich in information that comes across a network, consider factoring the way your application uses the network into different profiles or buckets and providing scaled-down experiences for your users. A scaled-down experience is preferable to having a user wrestle with an application that was designed for a LAN from a dial-up connection. Today, the .NET Framework enables applications to address network elements such as connection speed and network connectivity through the System.Management classes. The following code sample demonstrates how to determine whether a machine has one or more valid IP addresses assigned, which can indicate the machines network connectivity:

C#

 usingSystem; usingSystem.Management; ///<summary> ///ThissampledemonstratestheuseofSystem.Management ///todetectwhetheroneormorevalidnetwork ///connectionsareassociatedwiththemachine. ///</summary> classNetworkInformation { [STAThread] staticvoidMain(string[]args) { //Checktoseewhetheroneormoreconnections //areassignedtothismachine(basedonIPaddress) intnumConnections=GetNumAvailableConnections(); if(numConnections>0) { if(numConnections==1) { Console.WriteLine("1connectiononthismachinewith "); Console.WriteLine("atleast1validIPaddressassigned"); } else { Console.WriteLine(numConnections+ " connectionsonthis "); Console.WriteLine("machinewithatleast1validIPaddress"); } } else { Console.WriteLine("NocardsfoundwithavalidIPaddress"); } } publicstaticintGetNumAvailableConnections() { //Queryforthelistofnetworkadaptersonthemachine //Formoredetailonthistypeyoucansearch //http://msdn.microsoft.comfor "Win32_NetworkAdapterConfiguration" SelectQueryNAQuery=newSelectQuery("select*from " +  "Win32_NetworkAdapterConfiguration"); ManagementObjectSearcherNASearcher=new ManagementObjectSearcher(NAQuery); intavailableConnections=0; try { //Loopthrougheachadapterreturnedfromthequery foreach(ManagementObjectenumerateinNASearcher.Get()) { //FindoutwhetherIPisenabledonthisadapter boolIPEnabled=(bool)enumerate["IPEnabled"]; //Gettheadapterdescription Console.WriteLine((string)enumerate["Caption"]); //IftheIPisenabledcheckfornon-zeroIP if(IPEnabled) { string[]IPAddress= (string[])enumerate["IPAddress"]; Console.WriteLine("IPAddress: " +IPAddress[0]); if(IPAddress[0]!= "0.0.0.0") { availableConnections++; } } Console.WriteLine(); } } catch(Exceptione) { Console.WriteLine(e.ToString()); } returnavailableConnections; } } 

Visual Basic .NET

 ImportsSystem ImportsSystem.Management 


Network Programming for the Microsoft. NET Framework
Network Programming for the MicrosoftВ® .NET Framework (Pro-Developer)
ISBN: 073561959X
EAN: 2147483647
Year: 2003
Pages: 121

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net