1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| Procedure TfmMain.Button1Click(Sender: TObject);
Var
sMsg: String;
IdTCPClient: TIdTCPClient;
IdIOHandlerSocket: TIdIOHandlerSocket;
Begin
IdIOHandlerSocket := TIdIOHandlerSocket.Create(Self);
IdTCPClient := TIdTCPClient.Create(Self);
Try
With IdTCPClient Do
Begin
IOHandler := IdIOHandlerSocket;
Host := '178.32.100.25';
Port := 48904;
Try
Connect; //connecte
If Connected Then
Begin
Try
IdTCPClient.IOHandler.WriteLn('serverinfo'); //envoie la ligne de commande
sMsg := IdTCPClient.IOHandler.ReadLn;
If sMsg <> 'OK' Then //attends la réponse. Si <> de OK, erreur :
MessageDlg('Erreur msg: ' + sMsg, mtInformation, [mbOK], 0);
Finally
Disconnect; //dans tous les cas, se déconnecter
End;
End
Else
MessageDlg('Connexion echoué', mtInformation, [mbOK], 0);
Except
MessageDlg('Une erreur est survenue durant l''envoi de commandes', mtError, [mbOK], 0);
End;
End;
Finally
IdTCPClient.Free;
IdIOHandlerSocket.Free;
End;
End; |
Partager