Socket.timeout property doesn't work

March 27th, 2010 by Steven Sacks

AS3's Socket class has a public property called timeout, and it doesn't work.

The default value of timeout is 20000 milliseconds. Setting timeout to any other value doesn't change the 20000 millisecond timeout.

You can confirm this easily by attempting to connect to a Socket that doesn't respond. It will always take 20000 milliseconds for it to timeout, even if you set the timeout to a much smaller value, say 1000 or 5000.

There is a workaround.

1. Make your own Timer and listen for TimerEvent.TIMER_COMPLETE.
2. Start the timer as soon as you call connect().
3. In the Event.CONNECT listener, reset the timer.
4. If the TIMER_COMPLETE event fires first, close the socket.

Posted in AS3, Bugs

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

About Steven Sacks

I am a professional Flash developer with over 13 years of programming experience. I have consulted for high-profile agencies and companies in San Francisco, Los Angeles, Atlanta and New York, and developed numerous award-winning websites and rich internet applications for clients including Adobe, Fox Sports, FX Networks, Anheuser-Busch, GE, DirecTV, ESPN, The Weather Channel, Home Depot, and Coca-Cola.

I am the author of the open-source Gaia Framework for Adobe Flash, which dramatically reduces development time and makes developing Flash sites much easier.