Solved

Flex Air Internet connectivity

Posted on 2011-03-17
5
543 Views
Last Modified: 2013-11-19
Hi All,

I have a problem with internet connectivity i.e

1. My application is completely dependent on internet
2. On app start up i am calling some services...it works fine if initially internet connection is available
..a timer is set if internet connection is not available...
If on app start up internet conn is not available..&  there is a timer to recheck the internet...
if it is available after 5min or so.....
There is a problem in services that is i am not getting the result.....i.e the result event is not getting triggered..

Pls let me know where i am wrong..... Is there a problem in call web services using SOAP requests...but it works fine if net is available on app start up but...if available after some time this problem occurs,...
Below is the code snippet...


 
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication  xmlns:fx="http://ns.adobe.com/mxml/2009" 
						xmlns:s="library://ns.adobe.com/flex/spark" 
					   	xmlns:mx="library://ns.adobe.com/flex/mx" 
						xmlns:local="*" creationComplete="checkNetworkConnection(); 
						xmlns:xmlpathcommunicationport="services.xmlpathcommunicationport.*"
						>
	<fx:Style source="css/styles.css" />
	
	<fx:Declarations>
		<!--Call responder for Reference Page to get XML path-->
		<s:CallResponder id="getXmlPathLinkReferenceResult"/>
		<xmlpathcommunicationport:XmlPathCommunicationPort id="xmlPathCommunicationPort"/>
		<s:CallResponder id="getXmlPathLinkJudgementsResult"/>
		<s:CallResponder id="getXmlPathLinkAuthoritiesResult"/>
		<s:CallResponder id="getXmlPathLinkBillsResult"/>
		<s:CallResponder id="getXmlPathLinkOrdinanceResult"/>
		<s:CallResponder id="getXmlPathLinkNotificationsResult"/>
		
	</fx:Declarations>

	<fx:Script>
		<![CDATA[
		
		protected function init():void
		{
			//Reference get xmlPath for buttons
			getXmlPathLinkReferenceResult.token = xmlPathCommunicationPort.getXmlPathLink("references", "bare acts");
			getXmlPathLinkReferenceResult.addEventListener(ResultEvent.RESULT,getBareActs);
			
		}
		
		//result handler works only when initially internet connection is there, 
if internet connection is not there on app startup & if available after 5min there is problem with
 services that is i am not getting the result 
	
		private function getBareActs(event:ResultEvent):void{
			var result:String = event.result.toString();
			trace(result);
		}
			
			// Check for internet availability

			private var networkAvailable : Boolean = false;
			
			private function checkNetworkConnection() : void
			{
				var request:URLRequest = new URLRequest();
				request.method = "HEAD";
				request.url = "http://www.google.com"; 
				var urlLoader:URLLoader = new URLLoader();
				urlLoader.addEventListener( HTTPStatusEvent.HTTP_STATUS, connectHttpStatusHandler );
				urlLoader.addEventListener( IOErrorEvent.IO_ERROR, connectErrorHandler ); 
				urlLoader.load( request); 
			}
			
			private function connectHttpStatusHandler( event:HTTPStatusEvent):void
			{
				networkAvailable = ( event.status == 0 ? false : true );
				handleNetworkChange();
			}
			
			private function connectErrorHandler(event:IOErrorEvent):void
			{
				networkAvailable = false;
			}
			private var timer:Timer = new Timer(5000);
			private function handleNetworkChange() : void
			{
				if( networkAvailable ) {
					init();
					trace( "Online" );
				} else {
					
					timer.addEventListener(TimerEvent.TIMER,recheckInternetConnection);
					timer.start();
					trace( "Offline" );
				}
			}
			
			private function recheckInternetConnection(event:TimerEvent):void{
				timer.removeEventListener(TimerEvent.TIMER,recheckInternetConnection);
				checkNetworkConnection();
			}
		]]>
	</fx:Script>
	
</s:WindowedApplication>

Open in new window

0
Comment
Question by:SreeramojuPradeep
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:Plucka
ID: 35154396
After the first 5 seconds, I dont see where you start the timer again, that may be the problem.

do you need

handleNetworkChange();

in

connectErrorHandler
0
 

Author Comment

by:SreeramojuPradeep
ID: 35154615
Hi,
i checked by using the below code to restart the timer  but the problem persists..its not solved

private function connectErrorHandler(event:IOErrorEvent):void
                  {
                        networkAvailable = false;
                        handleNetworkChange();
                  }

is there any solution
0
 
LVL 18

Expert Comment

by:Plucka
ID: 35154779
Does the timer event fire?

Put a trace in each method and see if it fires.

Or put in a breakpoint and see whats going on in the debugger.
0
 

Accepted Solution

by:
SreeramojuPradeep earned 0 total points
ID: 35154903
Yes the timer event is getting fired properly and also the init() method is called....

i.e...protected function init():void
            {
                  //Reference get xmlPath for buttons
                  getXmlPathLinkReferenceResult.token = xmlPathCommunicationPort.getXmlPathLink("references", "bare acts");
                  getXmlPathLinkReferenceResult.addEventListener(ResultEvent.RESULT,getBareActs);
                  
            }

But there is a problem in sending the request.....i am not able to call any service i.e send any request...
i checked with back end...all parameters are proper but i dont know where it is going wrong....
If there is net conn available it works all fine...
But if net connection is not available on app start up this problem ocurs...

Is there any problem in WSDL calling, because the request itself is not going...


0
 

Author Closing Comment

by:SreeramojuPradeep
ID: 38435897
Thankx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now