Solved

Flex Air Internet connectivity

Posted on 2011-03-17
5
548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

751 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