title: System.Net.Sockets.SocketException (0x80004005)
body: <p>I'm writing a bot for moderating my twitch.tv channel in C#.</p>
  
  <p>Here's the basic code for the loop, which is done by a background worker to avoid UI freezes.  There's a TCPClient (Client), StreamReader (Reader), StreamWriter (Writer), and NetworkStream (Stream).</p>
  
  <pre><code>    private void listener_dowork(object sender, DoWorkEventArgs e)
      {
          string Data = "";
          while ((Data = Reader.ReadLine()) != null)
          {
              //Perform operations on the received data
          }
          Console.WriteLine("Loop ended");//this shouldn't happen
      }
      private void listener_workercompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          //basically, display a console message that says "OOPS!" and try to reconnect.
      }
  </code></pre>
  
  <p>I get the message "Loop ended" and "OOPS!" and at that point, I get the exception (which I cannot for the life of me catch).</p>
  
  <p>The thing is, I can physically unplug the network cable from my computer wait 30 seconds and plug it back in, and it'll continue just fine.</p>
  
  <p>The full exception is:</p>
  
  <pre><code>System.Net.Sockets.SocketException (0x80004005): An established connection was aborted by the software in your host machine
     at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
     at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
  </code></pre>
  
  <p>Note the lack of a line number, which is present in every other kind of exception I've had, which means I have no idea which part of the program is causing the exception, even though I've put every possible line inside a try/catch.</p>
  
  <p>I guess what I'm looking for is some insight into why this is occurring.</p>
  
  <p>It happens invariably every time I start the bot and leave it running for a few minutes on any channel, though the number of minutes varies.</p>