简体   繁体   中英

Delphi Indy Ping Error 10040 after upgrade from XE3 to XE4

I created a Ping function that utilizes the Indy TIdIcmpClient object. It has worked flawlessly for years. After upgrading from XE3 to XE4 the same code is now generating error 10040 (Message too long).

I read other posts concerning this error and the proposed solutions, but none of them have worked with 100% success.

I have reduced packet size to 32, 24, 12 and even 0, but still get the 10040 error.

I tried using the optional parameter "Buffer" which worked a little bit but occasionally causes other exceptions.

Anyone have any ideas on how to fix this?

Here's my code:

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;

Thanks for your time,

Tad

TIdIcmpClient修复程序已在开发中,但尚未发布,目前我还没有针对该版本的ETA。

you must set ABuffer, eg:

            Host := 'some.server.net';
            PacketSize := 24;
            ReceiveTimeout := 200;
            ABuffer := Host + StringOfChar(' ', 255);
            Ping(ABuffer);

Jan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM