我创建了一个使用Indy TIdIcmpClient对象的Ping函数。它已经完美运行多年。从XE3升级到XE4后,相同的代码现在会生成错误10040(消息太长)。Delphi Indy Ping从XE3升级到XE4后出现错误10040
我读过关于这个错误和提出的解决方案的其他帖子,但他们都没有100%的成功。
我已经减少了数据包大小到32,24,12甚至0,但仍然得到10040错误。
我尝试使用可选参数“缓冲区”,它工作一点点,但偶尔会导致其他异常。
任何人有任何想法如何解决这个问题?
这里是我的代码:
function Ping(Host: String;Timeout: Integer;ShowError: Boolean; out ErrorText: String): Boolean;
var
IdIcmpClient1: TIdIcmpClient;
Reply: TReplyStatusTypes;
ErrorFlag: Boolean;
ABuffer: String;
begin
Result:=False;
ErrorText:='Success';
ErrorFlag:=False;
Reply:=rsEcho;
ABuffer:=Host+StringOfChar(' ',255);
IdIcmpClient1:=TIdIcmpClient.Create;
IdIcmpClient1.PacketSize:=32;
IdIcmpClient1.Host:=Host;
IdIcmpClient1.ReceiveTimeout:=Timeout;
try
try
IdIcmpClient1.Ping(ABuffer);
except
on E: Exception do
begin
ErrorFlag:=True;
ErrorText:=E.Message;
if ShowError then MessageDlg('Ping Error: '+E.Message, mtWarning, [mbOK], 0);
end;
end;
if not ErrorFlag then
begin
try
Reply:=IdIcmpClient1.ReplyStatus.ReplyStatusType;
except
on E: Exception do
begin
ErrorFlag:=True;
ErrorText:=E.Message;
if ShowError then MessageDlg('Ping Reply Error: '+ErrorText, mtWarning, [mbOK], 0);
end;
end;
end;
if not ErrorFlag then
begin
Result:=Reply=rsEcho;
if not Result then
begin
case Reply of
rsEcho: ErrorText:='rsEcho';
rsError: ErrorText:='rsError';
rsTimeOut: ErrorText:='rsTimeOut';
rsErrorUnreachable: ErrorText:='rsErrorUnreachable';
rsErrorTTLExceeded: ErrorText:='rsErrorTTLExceeded';
rsErrorPacketTooBig: ErrorText:='rsErrorPacketTooBig';
rsErrorParameter: ErrorText:='rsErrorParameter';
rsErrorDatagramConversion: ErrorText:='rsErrorDatagramConversion';
rsErrorSecurityFailure: ErrorText:='rsErrorSecurityFailure';
rsSourceQuench: ErrorText:='rsSourceQuench';
rsRedirect: ErrorText:='rsRedirect';
rsTimeStamp: ErrorText:='rsTimeStamp';
rsInfoRequest: ErrorText:='rsInfoRequest';
rsAddressMaskRequest: ErrorText:='rsAddressMaskRequest';
rsTraceRoute: ErrorText:='rsTraceRoute';
rsMobileHostReg: ErrorText:='rsMobileHostReg';
rsMobileHostRedir: ErrorText:='rsMobileHostRedir';
rsIPv6WhereAreYou: ErrorText:='rsIPv6WhereAreYou';
rsIPv6IAmHere: ErrorText:='rsIPv6IAmHere';
rsSKIP: ErrorText:='rsSkip';
else
ErrorText:='Unknown';
end;
if ShowError then MessageDlg('Ping Error: '+ErrorText, mtWarning, [mbOK], 0);
end;
end;
finally
IdIcmpClient1.Free;
end;
end;
感谢您的时间,
塔德
嗨雷米。你能给我们一个关于修复的更新吗? –
我没有时间去处理它们。 –
@RemyLebeau,现在是2014年2月,我正在使用带有Indy10 TIdIcmpClient Ping()的C++ Builder XE5,并且此问题仍然存在。你们是否正在研究这个问题或者已经发布了更新/修复? –