Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2482 connectés 

  FORUM HardWare.fr
  Programmation
  Delphi/Pascal

  [Indy10] Comment PINGer?

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Indy10] Comment PINGer?

n°1276653
fredtheman
Posté le 04-01-2006 à 00:22:22  profilanswer
 

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 :
  1. procedure TForm1.Timer1Timer(Sender: TObject);
  2. var
  3.   RepStatus: TReplyStatus;
  4. begin
  5.   //PING host  
  6.   //IdIcmpClient1.Host := '127.0.0.1';  
  7.   //IdIcmpClient1.ReceiveTimeout := 2000; //2 seconds  
  8.   //IdIcmpClient1.Ping;  
  9.   //Works in Indy Delphi 7, no longer works in Indy 10  
  10.   //"Undeclared identifier: 'ReplyStatus'"  
  11.   {
  12.   if IdIcmpClient1.ReplyStatus.ReplyStatusType=rsTimeOut then begin
  13.     Label1.Caption :='Server dead @ ' + TimeToStr(Time);
  14.   end else begin
  15.     Label1.Caption :='Server alive @ ' + TimeToStr(Time);
  16.   end;
  17.   }
  18.   //Doesn't work in Indy 10  
  19.   //"Undeclared identifier: 'ReplyStatus'"  
  20.   {
  21.   if (IDIcmpClient1.ReplyStatus.BytesReceived > 0) then begin
  22.     ShowMessage('Server alive');
  23.   end else begin
  24.     ShowMessage('Server dead');
  25.   end;
  26.   }
  27.   //Doesn't work in Indy 10 : always returns "dead"  
  28.   //RepStatus := IDIcmpClient1.Receive(2000);  
  29.   //if (RepStatus.BytesReceived > 0) then  
  30.   {
  31.   if (RepStatus.ReplyStatusType = rsTimeOut) then
  32.     Label1.Caption := 'Server dead @ ' + TimeToStr(Time)
  33.   else
  34.     Label1.Caption := 'Server alive @ ' + TimeToStr(Time)
  35.   }
  36.   //Doesn't work in Indy 10  
  37.   {
  38.   IdIcmpClient1.Host := '127.0.0.1';
  39.   //TTL = unknown in Indy 10  
  40.   //IdIcmpClient1.TTL := 1000;  
  41.   IdIcmpClient1.ReceiveTimeout := 5000;
  42.   IdIcmpClient1.Ping;
  43.   case IdIcmpClient1.ReplyStatus.ReplyStatusType of
  44.     rsEcho:
  45.       begin
  46.         Label1.Caption := format('response from host %s in %d millisec.',
  47.         [
  48.         IdIcmpClient1.ReplyStatus.FromIpAddress,
  49.         IdIcmpClient1.ReplyStatus.MsRoundTripTime
  50.         ]);
  51.       end;
  52.     rsError:
  53.       Label1.Caption := 'Unknown error.';
  54.     rsTimeOut:
  55.       Label1.Caption := 'Timed out.';
  56.     rsErrorUnreachable:
  57.       Label1.Caption := format('Host %s reports destination network unreachable.', [IdIcmpClient1.ReplyStatus.FromIpAddress]);
  58.     rsErrorTTLExceeded:
  59.       Label1.Caption :=  format('Hope %d %s: TTL expired.', [IdIcmpClient1.TTL,IdIcmpClient1.ReplyStatus.FromIpAddress]);
  60.   end; // case  
  61.   }
  62. end;


 
Merci  
Fred.

mood
Publicité
Posté le 04-01-2006 à 00:22:22  profilanswer
 

n°1276655
Profil sup​primé
Posté le 04-01-2006 à 00:38:01  answer
 

je ne connais pas ce language, mais au cas ou essaye == au lieu de =

n°1277124
fredtheman
Posté le 04-01-2006 à 19:19:04  profilanswer
 


 
Pourtant, on est dans le forum Delphi/Pascal ;-) Non, c'est bien = pour la comparaison (et := pour l'assignation).
 
Le problème vient d'un changement dans Indy:  
 

Citation :


"The ReplyStatus and ReplyData properties still exist.  However, for whatever reason, they are declared as 'protected' in Indy 10, so you will have to edit IdIcmpClient.pas to move them back to 'public'.  Or else derive a new component to promote them to 'public'.
 
More accurately, a new IdCustomIcmpClient class was introduced in Indy 10, and the properties are declared as 'protected' in it.  It looks like an oversight that TIdIcmpClient does not promote them to 'public'.  This has been fixed in the current snapshot."


 
Les joies de l'open-source combiné à un support payant...
 
Merci
Fred.

n°1277183
Profil sup​primé
Posté le 04-01-2006 à 20:45:51  answer
 

fredtheman a écrit :

Pourtant, on est dans le forum Delphi/Pascal ;-) Non, c'est bien = pour la comparaison (et := pour l'assignation).


j'ai jamais fait de Delphi justement, j'ai juste essayé d'aider :) (juste VB mais ca fait un bail et je suis bien content de plus en faire)


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Delphi/Pascal

  [Indy10] Comment PINGer?

 

Sujets relatifs
Pinger une série d'url.....[PHP] Pinger une adresse DNS et retourner un gif 'online' ou 'offline'
Pinger un serveur en php ?[JAVA/RESEAUX] pinger / Problème avec les flux
Plus de sujets relatifs à : [Indy10] Comment PINGer?


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)