title: C# An established connection was aborted by the software in your host machine
body: <p>These errors are getting more and more frequent on my Game Server. They are causing the server to keep closing and restarting...</p>
  
  <pre class="lang-none prettyprint-override"><code>System.Net.Sockets.SocketException (0x80004005): An established connection was aborted by the software in your host machine 
     at System.Net.Sockets.Socket.BeginSend(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state) 
     at iRP.Game.Sessions.Session.SendData(Byte[] Data)
  </code></pre>
  
  <p>This is the code from which these errors are generated:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public void SendData(byte[] Data)
  {
      try
      {
          if (mSocket == null)
          {
              //Output.WriteLine("[SND] Socket has a null exception, which means it is now invalid. Remove this socket!", OutputLevel.CriticalError);
          }
          else
          {
              mSocket.BeginSend(Data, 0, Data.Length, SocketFlags.None, sendCallback, mSocket);
          }
      }
      catch (Exception e)
      {
          string WhatToWrite = "Error handled (SESSION): " + e.ToString() + "\n\n" + e.Message + "\n\nStack: " + e.StackTrace + Environment.NewLine + "\n\n";
          File.AppendAllText(Environment.CurrentDirectory + "\\data\\fatal.txt", WhatToWrite);
          Program.Stop();
      }
  }
  </code></pre>
  
  <p>The buffer sizes are correctly set, we are using KeepAlive on the socket and were using Send and Receive Timeouts.</p>
  
  <p>People suggested that disabling the firewall would help, but whenever I do this our Game Server (Dedicated Server) restarts itself as if it's under attack, so the firewall must remain enabled.</p>
  
  <p>Anyone else got any other solutions for this?</p>
  
  <p>PS: We are behind DDoS Mitigation Services which may be limiting the number of connections...</p>