|
unit clconexion;
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes,IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient;
|
|
|
|
type
|
|
ThrConexion = class(TThread)
|
|
private
|
|
{ Private declarations }
|
|
|
|
fcodigo:integer;
|
|
fhost,fcomando:string;
|
|
fcliente:TIdTcpClient;
|
|
fpuerto:integer;
|
|
|
|
protected
|
|
procedure Execute; override;
|
|
public
|
|
constructor Create(puerto,codigo:integer;host,comando:string);
|
|
end;
|
|
|
|
|
|
implementation
|
|
constructor ThrConexion.Create(puerto,codigo:integer;host,comando:string);
|
|
begin
|
|
inherited Create(true);
|
|
fcodigo:=codigo;
|
|
fpuerto:=puerto;
|
|
//Eliminar más adelante host
|
|
fhost:=host;
|
|
//fhost:='localhost';
|
|
fcomando:=comando;
|
|
FreeOnTerminate:=True;
|
|
end;
|
|
|
|
procedure ThrConexion.Execute;
|
|
begin
|
|
try
|
|
fcliente:=TidTcpClient.create(nil);
|
|
fcliente.Host:=fhost;
|
|
fcliente.port:=fpuerto;
|
|
fcliente.connect;
|
|
try
|
|
fcliente.GetResponse(200);
|
|
fcliente.sendCmd(fcomando,fcodigo);
|
|
finally
|
|
fcliente.Disconnect;
|
|
fcliente.free;
|
|
end;
|
|
except
|
|
//writeLn('Error al enviar el comando');
|
|
end;
|
|
end;
|
|
|
|
end.
|