Details on breaking through the two http connection limits per client in.net

  • 2020-05-12 03:05:27
  • OfStack

In the Http protocol, it is stipulated that the maximum number of concurrent connections requested by the same Http is 2.
Today's browsers no longer follow this restriction, but System.Net on the Dot Net platform still follows this standard by default.
As a result, when using HttpWebRequset or WebClient to visit a website by using multithreading, the connection is often closed abnormally, which greatly reduces the efficiency.
The value of this limit can be set or configured.
System. Net. ServicePointManager. DefaultConnectionLimit is set up. You can set the size of this value according to the actual situation, but it is recommended not to exceed 1024, and 512 is recommended, which is enough.
Of course, you can configure this value directly in the program app.config.
Once this value is set, it is only valid for subsequent HTTP requests.
Two approaches:
1. Restrict the application domain to use a different application domain for each thread:

AppDomain appDomain = AppDomain.CreateDomain("");
appDomain.ExecuteAssembly(@"TestClient.exe");
AppDomain.Unload(appDomain);

2. In the app.config profile add:

<system.net>
 <connectionManagement>
  <add address="*" maxconnection="100"/>
 </connectionManagement>
</system.net>


Related articles: