title: Detect TCP connection close when playing Flash video
body: <p>On the Flash client side, how do I detect when the server purposely closes the TCP connection to its video stream? I'll need to take action when this occurs - maybe attempt to restart the video or display an error message. Currently, the connection closing and the connection being slow look the same to me. The <code>NetStream</code> object ushers a <code>NetStream.Play.Stop</code> event in both cases. When the connection is slow, it usually recovers by itself within seconds. I wish to only take action when the connection is closed, not when it is slow. </p>
  
  <p>Here's how my general setup looks like. It's the basic <code>NetConnection</code>-><code>NetStream</code>-><code>Video</code> setup.</p>
  
  <pre><code>this.vidConnection = new NetConnection();
  this.vidConnection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this.connectionAsyncError);
  this.vidConnection.addEventListener(IOErrorEvent.IO_ERROR, this.connectionIoError);
  this.vidConnection.addEventListener(NetStatusEvent.NET_STATUS, this.connectionNetStatus);
  this.vidConnection.connect(null);
  this.vidStream = new NetStream(this.vidConnection);
  this.vidStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, this.streamAsyncError);
  this.vidStream.addEventListener(IOErrorEvent.IO_ERROR, this.streamIoError);
  this.vidStream.addEventListener(NetStatusEvent.NET_STATUS, this.streamNetStatus);
  this.vid.attachNetStream(this.vidStream);
  </code></pre>
  
  <p>None of the error events fire when the server closes the TCP or when the connection freezes up. Only the <code>NetStream.Play.Stop</code> event fires. Here's a trace of what happens from initially playing the video to the TCP connection closing.</p>
  
  <pre><code>connection net status = NetConnection.Connect.Success
  playStream(http://192.168.0.44/flv/4d29104a9aefa)
  NetStream.Play.Start
  NetStream.Buffer.Flush
  NetStream.Buffer.Full
  NetStream.Buffer.Empty
  checkDimensions 0 0
  onMetaData
  NetStream.Buffer.Full
  NetStream.Buffer.Flush
  checkDimensions 960 544
  NetStream.Buffer.Empty
  NetStream.Buffer.Flush
  NetStream.Play.Stop
  </code></pre>
  
  <p>When I do a dump on various properties during the connection closing and connection being slow, I see no distinctive values that could help me differentiate closing and slowness.</p>
  
  <pre><code>NetConnection-&gt;connected = true
  NetConnection-&gt;connectedProxyType = none
  NetConnection-&gt;proxyType = none
  NetConnection-&gt;uri = null
  NetConnection-&gt;usingTLS = false
  VidStream-&gt;bufferLength = 0
  VidStream-&gt;bufferTime = 0.1
  VidStream-&gt;bytesLoaded = 3204116
  VidStream-&gt;bytesTotal = 3204116
  VidStream-&gt;currentFPS = 0
  VidStream-&gt;time = 63.797
  </code></pre>