Status Servidor Datasnap

Android

Delphi

06/09/2016

Pessoal estou desenvolvendo uma aplicação de Vendas Mobile para Android, usando DELPHI XE8 e DATASNAP para trafegar os dados, porem antes de fazer o sincronismo, estou fazendo uma função para verificar se o servidor DATASNAP esta ativo, porem ela demora demais para retornar o erro de conexão, e quando retorna trava a aplicação inteira precisando fechar a mesma, segue função abaixo, se alguem puder me ajudar ou se conhecer uma forma melhor de testar o acesso a este servidor:

procedure TForm1.STATUS_SERVIDOR;
begin
QRYAUX_INT.Close;
QRYAUX_INT.SQL.Clear;
QRYAUX_INT.SQL.Add('SELECT * FROM CONFICURACAO');
QRYAUX_INT.Open;

if QRYAUX_INT.FieldByName('HOST_SERVIDOR').AsString = '' then
begin
ShowMessage('Dados para conexão não encontardos');
ABORT;
end;

with SQLTeste do
begin
if Connected then
Connected := False;
LoginPrompt := False;
LoadParamsOnConnect := False;
KeepConnection := True;
LibraryName := EmptyStr;
Params.Values['port'] := QRYAUX_INT.FieldByName('PORTA_SERVIDOR').Value;
Params.Values['hostname'] := QRYAUX_INT.FieldByName('HOST_SERVIDOR').AsString;
Params.Values['communicationprotocol'] := 'tcp/ip';
Params.Values['DSAuthenticationUser'] := '';
Params.Values['DSAuthenticationPassword'] := '';
end;
try
SQLTeste.Open;
except
on e: exception do
begin
ShowMessage('Erro - ' + e.Message);
end;
end;
end;

O componente SQLTeste é do tipo TSQLConection.
Softsan Software

Softsan Software

Curtidas 0

Respostas

Softsan Software

Softsan Software

06/09/2016

Pessoal acabei resolvendo da seguinte forma:

function TForm1.ServerAtivo(AHost: String; APort: Integer) : Boolean;
Var
VCon : TIdTCPClient;
begin
result := false;

VCon := TIdTCPClient.create;
try
VCon.ReadTimeout := 9000;
VCon.ConnectTimeout := 9000;
VCon.Port := APort;
VCon.Host := AHost;
VCon.Connect;
VCon.Disconnect;

result := true;
finally
VCon.DisposeOf;
end;
end;
GOSTEI 0
POSTAR