title: Why System.Net.ServicePoint.ConnectionLimit uses '7FFFFFFF' (Int32.MaxValue/2147483647) when a client connects to a service on 'localhost'?
body: <p>Why  System.Net.ServicePoint.ConnectionLimit uses <strong>'7FFFFFFF' (Int32.MaxValue/2147483647)</strong> when a client connects to a service on <strong>'localhost'</strong>, whereas it decide to use '2' as default if the service is running on remote machine?</p>
  
  <p>Initially I thought it will be ServicePointManager.DefaultConnectionLimit if servicepoint.connectionlimit is not set. However, I just realized (once I got an issue from customer), that its Int32.MaxValue/2147483647. </p>
  
  <p>I have done some research (for details please refer to below links), however I couldn't find out why it uses to int32.maxvalue. I can kind of conjecture its probably for better performance as the input requests and response messages are not going across boundary. </p>
  
  <p><strong>My Question(s):</strong></p>
  
  <ol>
  <li>Why Int32.MaxValue if the service is running on <strong>'localhost'</strong>?
  (any explanation in English ;) of the code snippet I copied from reflector is also great - as I kind of conjectured the intentions - but didn't understand the code totally :))</li>
  <li>I understand its for perf - but from '2' (default) to 'int32.maxvalue' sounds stretch to me. In other words why is it ok to open as many TCP connections as long as the requests are not going across network.
  (in other words - why default to int32.maxvalue - doesn't it have side affects)</li>
  </ol>
  
  <p><strong>Some useful links related to this:</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/22800216/how-and-where-the-tcp-connection-has-been-created-in-httpwebrequest-and-how-is">How and where the TCP connection has been created in httpwebrequest, and how is it related to servicepoint?</a></p>
  
  <p><a href="http://blogs.microsoft.co.il/idof/2011/06/20/servicepointmanagerdefaultconnectionlimit-2-depends/" rel="nofollow noreferrer">http://blogs.microsoft.co.il/idof/2011/06/20/servicepointmanagerdefaultconnectionlimit-2-depends/</a></p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/system.net.servicepoint.connectionlimit(v=vs.110).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.net.servicepoint.connectionlimit(v=vs.110).aspx</a></p>
  
  <p><a href="http://arnosoftwaredev.blogspot.com/2006/09/net-20-httpwebrequestkeepalive-and.html" rel="nofollow noreferrer">http://arnosoftwaredev.blogspot.com/2006/09/net-20-httpwebrequestkeepalive-and.html</a></p>
  
  <p><strong>Code Snippet from Reflector</strong></p>
  
  <pre><code>  public int ConnectionLimit
          {
              get
              {
                  if ((!this.m_UserChangedLimit &amp;&amp; (this.m_IPAddressInfoList == null)) &amp;&amp; (this.m_HostLoopbackGuess == TriState.Unspecified))
                  {
                      lock (this)
                      {
                          if ((!this.m_UserChangedLimit &amp;&amp; (this.m_IPAddressInfoList == null)) &amp;&amp; (this.m_HostLoopbackGuess == TriState.Unspecified))
                          {
                              IPAddress address = null;
                              if (IPAddress.TryParse(this.m_Host, out address))
                              {
                                  this.m_HostLoopbackGuess = IsAddressListLoopback(new IPAddress[] { address }) ? TriState.True : TriState.False;
                              }
                              else
                              {
                                  this.m_HostLoopbackGuess = NclUtilities.GuessWhetherHostIsLoopback(this.m_Host) ? TriState.True : TriState.False;
                              }
                          }
                      }
                  }
                  if (!this.m_UserChangedLimit &amp;&amp; !((this.m_IPAddressInfoList == null) ? (this.m_HostLoopbackGuess != TriState.True) : !this.m_IPAddressesAreLoopback))
                  {
                      return 0x7fffffff;
                  }
                  return this.m_ConnectionLimit;
              }
              set
              {
                  if (value &lt;= 0)
                  {
                      throw new ArgumentOutOfRangeException("value");
                  }
                  if (!this.m_UserChangedLimit || (this.m_ConnectionLimit != value))
                  {
                      lock (this)
                      {
                          if (!this.m_UserChangedLimit || (this.m_ConnectionLimit != value))
                          {
                              this.m_ConnectionLimit = value;
                              this.m_UserChangedLimit = true;
                              this.ResolveConnectionLimit();
                          }
                      }
                  }
              }
          }
  </code></pre>
  
  <p>Regards,</p>