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 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.

Here is the 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.

 

One Response to Socket.timeout property doesn't work

  1. Larry Stamper says:

    Is it safe to close the socket when it could be in the middle of a read or write? Will putting a try-catch around it make it safe? Should I first remove my ConnectionHandler and SocketDadtHandler from THe Socket?

Leave a Reply

Set your Twitter account name in your settings to use the TwitterBar Section.