首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ServicePointManager.DefaultConnectionLimit是IP吗?

ServicePointManager.DefaultConnectionLimit是IP吗?
EN

Stack Overflow用户
提问于 2017-11-12 17:35:52
回答 1查看 209关注 0票数 0

我正在构建一个web爬虫,目标站点不允许来自同一个IP的两个以上并发连接。

我的计划是:我将购买一个带有4个额外弹性IP的EC2,以便更快地获取数据(将是10个并发连接,8个来自附加IP,2个来自“主”IP)。

我将使用BindIPEndPointDelegate (从here获取)设置源IP,然后开始下载页面。

因此,我的问题来了: DefaultConnectionLimit将应用于(每个源IP ),还是仅限于2个并发连接的整个应用程序?

EN

回答 1

Stack Overflow用户

发布于 2018-10-27 22:47:03

您需要指定主机,否则它将应用于所有主机:

使用配置:

代码语言:javascript
复制
<!-- By host -->
<configuration>
 <system.net>
  <connectionManagement>
   <add address="myapi.com" maxconnection="12"/>
   <add address="yourapi.com" maxconnection="8"/>
   <add address="74.125.236.199" maxconnection="4"/>
  </connectionManagement>
 </system.net>
</configuration>

<!-- All hosts -->
<configuration>
 <system.net>
  <connectionManagement>
   <add address="*" maxconnection="15"/>
  </connectionManagement>
 </system.net>
</configuration>

使用代码:

代码语言:javascript
复制
var apiServicePoint1 = ServicePointManager.FindServicePoint("myapi.com");

apiServicePoint1.ConnectionLimit = 12;

var apiServicePoint2 = ServicePointManager.FindServicePoint("yourapi.com");

apiServicePoint2.ConnectionLimit = 8;

参考资料:https://vincentlauzon.com/2015/12/13/beyond-2-concurrent-connections-in-net/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47251824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档