Close the Socket in Finally branch : Socket « Network « Flash / Flex / ActionScript






Close the Socket in Finally branch

 

package
{
    import flash.display.Sprite;
    import flash.errors.IOError;
    import flash.net.Socket;

    public class Main extends Sprite

    {
        public function Main()
        {
            try
            {
                var s:Socket = new Socket();
                s.connect("http://www.cmu.edu/", 80);
            } catch(error:IOError) {
                trace("I/O Error:", error.message);
            } catch(error:SecurityError) {
                trace("Security Error:", error.message);
            } finally {
                s.close();
            }
        }
    }
}

        








Related examples in the same category

1.Connecting to a Socket Server
2.Receiving Data
3.Handling a Built-in Exception
4.Sending Data
5.Handling Asynchronous Errors: IOErrorEvent