【问题标题】:Indy 10 TIdHttpServer missing MaxConnectionReply propertyIndy 10 TIdHttpServer 缺少 MaxConnectionReply 属性
【发布时间】:2013-04-06 00:53:35
【问题描述】:

我正在使用 Indy10,并使用派生自 TIdHttpServer 的类创建了一个 Web 服务器。在我的子类中,我重写了 DoMaxConnectionsExceeded 方法。当超过 MaxConnections 时,这似乎可以正常触发。

在早期的 Indy 版本中,至少根据 Remy Lebeau 的评论 hereTIdHttpServer 上有 MaxConnectionReply 属性。如果超出MaxConnections,这可用于创建自定义消息。 Indy 10 似乎并非如此。

当超过MaxConnections 时,Indy10 是否可以创建自定义消息?

【问题讨论】:

  • 不是您问题的答案,但您所说的不是真的:在同一线程中,您指出 Remy 解释说 TIdHttpServer 中没有 MaxConnectionReply 属性,如果您再次阅读,你会注意到胎面是关于 Indy 10,而不是 Indy 9。

标签: delphi indy indy10


【解决方案1】:

正如我在您链接到的线程中所述,MaxConnectionReply 是由 TIdCmdTCPServer 实现的,TIdHTTPServer 不是从其派生的。由于您要覆盖 DoMaxConnectionsExceeded(),因此您必须手动将自己的回复发送给客户端,并确保它是正确的 HTTP 格式,例如:

procedure TMyHttpServer.DoMaxConnectionsExceeded(AIOHandler: TIdIOHandler);
var
  Html: TIdBytes;
begin
  Html := ToBytes('<html><body>500 - Too many connections</body></html>');
  AIOHandler.WriteLn('HTTP/1.0 500 Too many connections');
  AIOHandler.WriteLn('Content-Type: text/html');
  AIOHandler.WriteLn('Content-Length: ' + IntToStr(Html));
  AIOHandler.WriteLn('Connection: close');
  AIOHandler.WriteLn;
  AIOHandler.Write(Html);
end;

【讨论】:

  • 抱歉这么久才回来。幸运的是,通过增加 MaxConnections 我没有遇到问题。但我想明白。我将 MaxConnections 设置得非常低,并验证 DoMaxConnectionsExceeded 过程是否已触发。使用您在上面提供的示例,我从未见过任何文字。所以我改为使用&lt;html&gt;&lt;body&gt;500 - Too many connections&lt;/body&gt;&lt;/html&gt;,这将显示消息。
  • 对不起,我的错。我忘记在 HTTP 回复中包含一些正文数据。我已经更新了我的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多