Solved

Flex Air Internet connectivity

Posted on 2011-03-17
5
536 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 27
How to silent print from safari browser 6 134
I starting with php 12 92
JQuery tracking event. 3 39
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

707 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

17 Experts available now in Live!

Get 1:1 Help Now