Delphi + Indy:连接正常关闭 [英] Delphi + Indy: Connection closed gracefully

查看:186
本文介绍了Delphi + Indy:连接正常关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用D7 + Indy 10最新版本。

Using D7 + Indy 10 latest build.

我的代码正在使用TIdSMTP发送电子邮件。
我在一些最终用户不断获得连接关闭,电子邮件从不发送。

My code is using TIdSMTP to send email. I keep getting "Connection closed gracefully" at some end-users, and the email is never sent.

代码如下:

try
~~~~
~~~~
_idSMTP := TIdSmtp.Create;
with _idSMTP do
begin
  Host := 'myhost';
  Connect;
  try
    Send(_EmailMsg);
    Result := True;
  except
    on E: Exception do
    begin
      MsgDlgErr(Self.Handle, E.Message)
    end
  end;
end;
finally
 _idSMTP.Disconnect;
 _idSMTP.Free;
end;

任何建议?

推荐答案

请阅读 http://www.swissdelphententer .ch / en / showarticle.php?id = 1


EIdConnClosedGracefully是一个
异常,表示
连接被
另外一方有意关闭。这不是
与破坏的连接相同,
会导致连接重置错误。
如果对方已经关闭了
连接,并且套接字被读取或
写入,EIdConnClosedGracefully
将由Indy提出。这是
,类似于尝试读取
到已经关闭的文件,而
您的知识。

EIdConnClosedGracefully is an exception signaling that the connection has been closed by the other side intentionally. This is not the same as a broken connection which would cause a connection reset error. If the other side has closed the connection and the socket is read or written to, EIdConnClosedGracefully will be raised by Indy. This is similar to attempting to read or write to a file that has been closed without your knowledge.

在某些情况下这是一个真正的例外
,你的代码需要处理它。在
其他情况(通常为服务器)中,
是协议的
的正常部分,Indy为您处理此
异常。即使Indy
捕获它,当在IDE
中运行时,调试器将被首先触发。
你可以简单地按F9继续
,而Indy将处理异常
,但在
调试期间不断的停止可能会令人讨厌。在
中,Indy捕获
异常的情况下,您的用户将永远不会在程序中看到
异常,除非
从IDE运行。

In some cases this is a true exception and your code needs to handle it. In other cases (typically servers) this is a normal part of the functioning of the protocol and Indy handles this exception for you. Even though Indy catches it, when running in the IDE the debugger will be triggered first. You can simply press F9 to continue and Indy will handle the exception, but the constant stopping during debugging can be quite annoying. In the cases where Indy catches the exception, your users will never see an exception in your program unless it is run from the IDE.

这篇关于Delphi + Indy:连接正常关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆