Solved

Flex Air Internet connectivity

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iOS retina Display, HTML Email Signature 5 525
MVC and Angular 2 114
Animated .jpg? 13 97
asp Google Map 2 32
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

861 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