Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Flex Air Internet connectivity

Posted on 2011-03-17
5
Medium Priority
?
554 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

721 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