Actionscript Socket Connection

Hi,

I want the flash movie to keep trying to connect to the server, so in the case if the server is offline, the client will connect whenever the server get online.

Additionally, I want it to do the same if it got disconnected for any reason.

I am using Actionscript 3 Socket class.
LVL 12
Mohamed AbowardaSoftware EngineerAsked:
Who is Participating?
 
dgofmanCommented:
You can try to loop with timeout by ping Google.com

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 );

private var interval:Number;
interval  = setInterval(recheckInternetConnection, 5000);

function recheckInternetConnection():void{
    urlLoader.load( request);
}

function connectHttpStatusHandler( event:HTTPStatusEvent):void{
     clearInterval(interval);
     trace(“CONNECTED”);
}
0
 
blue-genieCommented:
Hi, I don't know of any built in way to do this but why don't you use a timer to check at a specified interval whether socket connected - if not call the connect? not sure how efficient this will be in terms of processing but it should work if you don't find another way to do it.
0
 
dgofmanCommented:
You can use NetworkMonitoring but its available if you will run your SWF on AIR
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Mohamed AbowardaSoftware EngineerAuthor Commented:
@dgofman: I must run the swf on a website.

I want the page to be connected all the time and if the server is offline it keep trying to connect till the server come online.
0
 
Mohamed AbowardaSoftware EngineerAuthor Commented:
@dgofman: I am using Socket class, basically, I want to the socket to keep trying to connect until it establish the first connection.
0
 
dgofmanCommented:
The same idea, expect instead
urlLoader.load( request);
you will use
socket.connect(host, port);


http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
dgofmanCommented:
I am waiting an author responce
0
 
Mohamed AbowardaSoftware EngineerAuthor Commented:
It's working.

Thanks,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.