title: C# - an established connection was aborted by the software in your host machine Error
body: <p>I am building a Mock Server using TCPListener.</p>
  
  <p>When I tried to debug my code by running the client, I was able to read the request on the server. But on the client side, an exception is being thrown. Here is the exception I got from the trace:</p>
  
  <blockquote>
    <p>System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:05:00'. ---&amp;gt; System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---&amp;gt; System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine</p>
  </blockquote>
  
  <p>Here is the code of I implemented on the server:</p>
  
  <pre><code>TcpClient client = listener.AcceptTcpClient();
  NetworkStream nwStream = client.GetStream();
  byte[] buffer = new byte[client.ReceiveBufferSize];
  int bytesRead = nwStream.Read(buffer, 0, client.ReceiveBufferSize);
  var dataReceived = Encoding.ASCII.GetString(buffer, 0, bytesRead);
  
  byte[] sendBytes = null;
  try
  {
      var output = "POST HTTP/1.1 200 OK\r\n";
      output += "Server: Apache-Coyote/1.1\r\n";
      output += "Content-Type: application/soap+xml\r\n";
      output += "Content-Length: 632\r\n";
      output += "Date: Thu, 06 Aug 2015 02:06:39 GMT\r\n\r\n";
      output +=
          "&lt;S:Envelope xmlns:S=\"http://www.w3.org/2003/05/soap-envelope\"&gt;&lt;S:Header&gt;&lt;/S:Header&gt;&lt;S:Body&gt;&lt;/S:Body&gt;&lt;/S:Envelope&gt;";
      sendBytes = Encoding.ASCII.GetBytes(output);
      nwStream.Write(sendBytes, 0, sendBytes.Length);
      nwStream.Flush();
  }
  catch (SocketException se)
  {
      throw;
  }
  
  client.Close();
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>I also tried to disable my firewall but the exception still occurs.</p>