fredtheman | Bonjour, J'ai apparemment réussi à mettre à jour Indy dans mon D7 Enterprise (fallait le faire, pour investiguer une fuite de mémoire), mais ce code ne compile plus, et je n'ai pas réussi à trouver comment on fait dans Indy 10. Quelqu'un sait-il comment utiliser IdIcmpClient pour pinger un serveur? Comme vous pouvez le voir ci-dessous, j'ai essayé plusieurs trucs, mais rien ne fonctionne:
Code :
- procedure TForm1.Timer1Timer(Sender: TObject);
- var
- RepStatus: TReplyStatus;
- begin
- //PING host
- //IdIcmpClient1.Host := '127.0.0.1';
- //IdIcmpClient1.ReceiveTimeout := 2000; //2 seconds
- //IdIcmpClient1.Ping;
- //Works in Indy Delphi 7, no longer works in Indy 10
- //"Undeclared identifier: 'ReplyStatus'"
- {
- if IdIcmpClient1.ReplyStatus.ReplyStatusType=rsTimeOut then begin
- Label1.Caption :='Server dead @ ' + TimeToStr(Time);
- end else begin
- Label1.Caption :='Server alive @ ' + TimeToStr(Time);
- end;
- }
- //Doesn't work in Indy 10
- //"Undeclared identifier: 'ReplyStatus'"
- {
- if (IDIcmpClient1.ReplyStatus.BytesReceived > 0) then begin
- ShowMessage('Server alive');
- end else begin
- ShowMessage('Server dead');
- end;
- }
- //Doesn't work in Indy 10 : always returns "dead"
- //RepStatus := IDIcmpClient1.Receive(2000);
- //if (RepStatus.BytesReceived > 0) then
- {
- if (RepStatus.ReplyStatusType = rsTimeOut) then
- Label1.Caption := 'Server dead @ ' + TimeToStr(Time)
- else
- Label1.Caption := 'Server alive @ ' + TimeToStr(Time)
- }
- //Doesn't work in Indy 10
- {
- IdIcmpClient1.Host := '127.0.0.1';
- //TTL = unknown in Indy 10
- //IdIcmpClient1.TTL := 1000;
- IdIcmpClient1.ReceiveTimeout := 5000;
- IdIcmpClient1.Ping;
- case IdIcmpClient1.ReplyStatus.ReplyStatusType of
- rsEcho:
- begin
- Label1.Caption := format('response from host %s in %d millisec.',
- [
- IdIcmpClient1.ReplyStatus.FromIpAddress,
- IdIcmpClient1.ReplyStatus.MsRoundTripTime
- ]);
- end;
- rsError:
- Label1.Caption := 'Unknown error.';
- rsTimeOut:
- Label1.Caption := 'Timed out.';
- rsErrorUnreachable:
- Label1.Caption := format('Host %s reports destination network unreachable.', [IdIcmpClient1.ReplyStatus.FromIpAddress]);
- rsErrorTTLExceeded:
- Label1.Caption := format('Hope %d %s: TTL expired.', [IdIcmpClient1.TTL,IdIcmpClient1.ReplyStatus.FromIpAddress]);
- end; // case
- }
- end;
|
Merci Fred. |