Delphi & Datasnap - Connection Timeout, Communicataion Timeout or a way to avoid Client App to hang when no server response

放肆的年华 提交于 2020-03-02 05:44:34

问题


I am trying to use a Client-Server Datasnap based architecture. The client is inside an Android App that connects by Wifi with the Server Program which runs in a PC.

This are the server and client features:

Server Side:

Server Methods

TSQLConnection

  • Driver: Firebird.
  • KeepConnection: true.

Server Container

TDSServer

  • Queuesize: 100
  • ChannelresponseTimeout: 3000

TDSTCPServerTransport

  • BufferKBSize: 32
  • KeepAliveEnablement: kaDisabled
  • MaxThreads: 30
  • PoolSize: 10
  • Port: 211

Client Side

Main

TSQLConnection

  • Driver: Datasnap
  • ConnectTimeout:2000
  • CommunicationTimeOut:5000
  • DBXConnection constructor:

The function:

function TFrm_Principal.GetServerMethods1Client: TServerMethods1Client;
begin
  Conexion.Close;
  Conexion.Open;
  if FServerMethods1Client = nil then
  begin
    FServerMethods1Client := TServerMethods1Client.Create
      (Conexion.DBXConnection, FInstanceOwner);
  end;
  result := FServerMethods1Client;
end;

ClientClasses

  • Command Example (which off course has its equivalent at the server side)

The function:

function TServerMethods2Client.validaEstado(factura: string): Boolean;
begin
  try
    if FvalidaEstadoCommand = nil then
    begin
      FvalidaEstadoCommand := FDBXConnection.CreateCommand;
      FvalidaEstadoCommand.CommandType := TDBXCommandTypes.DSServerMethod;
      FvalidaEstadoCommand.Text := 'TServerMethods1.validaEstado';
      FvalidaEstadoCommand.Prepare;
    end;
    FvalidaEstadoCommand.CommandTimeout := 3;
    FvalidaEstadoCommand.Parameters[0].Value.SetWideString(factura);
    FvalidaEstadoCommand.ExecuteUpdate;
    Result := FvalidaEstadoCommand.Parameters[1].Value.GetBoolean;
  except
    on e: Exception do
    begin
      controlarError;
    end;
  end;
end;

Everything works very fine and fast, but when the Tablet looses Wifi connection with the Server, it hangs for more than the timeout time assigned in the different properties. Some times I wait for 30 or 40 seconds and there is no response. If I go closer to the network router, sometimes it recovers the flow, but if I stay away, the app finally crashes. The question is: why would it hang if there are timeouts which should make the app respond with a "could not connect to the network on time" or "timeout error" instead of just hanging with out any posibility for the user than waiting or restarting the app?

来源:https://stackoverflow.com/questions/35246305/delphi-datasnap-connection-timeout-communicataion-timeout-or-a-way-to-avoid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!