Link to home
Start Free TrialLog in
Avatar of cubicalmonkey
cubicalmonkey

asked on

Flash / Actionscript How to set socket timout()

I'm sure this is an easy question but I just cant seem to make it with with my junior AS3 skills.
Trying to figure out how to set the timeout on a binary socket connection.
Basically what I'm looking to do is attempt to reconnect to my socket if the first connection fails.
From what I've read and experience,  the default socket time out is 20 seconds which is much too long for me.
Id like to set this to say, 5 seconds.
Hoping this resolves some of the  flash "error #2048" problems I'm seeing.
Thanks for your help!

function startTest():void{
	Tbytes = 0;
	ExternalInterface.call( "updateStatus","Preparing download test");
	connectToSocket();
	stop();
}

function connectToSocket():void{
	s = new Socket(host, 7890);
	s.addEventListener(IOErrorEvent.IO_ERROR, showError);
	s.addEventListener(Event.CLOSE, closeHandler);
	s.addEventListener(Event.CONNECT, connectHandler);
	s.addEventListener(ProgressEvent.SOCKET_DATA, handleTcpData);
	s.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityError);
}


var connCounter	:Number = 0;

function securityError(event:Event):void {
	if(connCounter < 4){
		Security.loadPolicyFile("http://"+host+"/crossdomain.xml");
		connectToSocket();
		
	}else{
		ExternalInterface.call("logError","securityError:-Counter:"+connCounter + feedback,stripspaces(event.toString()));
	}
	connCounter ++;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of vindys80
vindys80
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cubicalmonkey
cubicalmonkey

ASKER

Ha!  simple yet I failed to correctly set it on my own.
Thanks for you help !