RTC Forums
November 01, 2024, 03:26:31 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Receiving: Error Connection problems, no response received  (Read 5115 times)
ClementDoss
RTC License
***
Posts: 36


« on: April 11, 2015, 11:53:54 PM »

Hi,

I have a rtcClient Multithread=True and rtcServer MultiThread = True.
My rtcClientModule (cmProcessFileApi ) has AutoSessions = True, AutosessionPing = 10, Compression = cMax.

This API is responsible for loading and processing files. All calls are blocking.

The client calls this code:
Code:
function TmdwClient.ProcessFile(const aFileName, aAction, aParameters: String;
  aFileData: TStream; var aLog: String): Boolean;
var
  lFunc : TRtcFunctionInfo;
  lRetval : TrtcValue;
begin
   lFunc := cmProcessFileAPI.Data.NewFunction('ProcessFile');
   lFunc.AsString['Action'] := aAction;
   lFunc.asString['Parameters'] := aParameters;
   lFunc.asString['Filename'] := ExtractFilename(aFileName);
   lFunc.asByteStream['FileData'] := aFileData;
   lRetVal := cmProcessFileAPI.Execute; // #1
   Result := False;
   aLog := '';
   if lRetval.isType = rtc_Record then begin
      aLog := lRetval.asRecord.asString['Log'];
      Result := lRetval.asRecord.asBoolean['Success'];
   end;
end;

The call will hang in #1 until the process is done. The user interface will have to wait until this event is done. This method is called from a ModalWindow so the application must wait until it returns. The file will be around 2.0 Mb.
The server gets the file with this code:
Code:
procedure TmdwServer.fncProcessFileExecute(Sender: TRtcConnection;
  Param: TRtcFunctionInfo; Result: TRtcValue);
var
  lAction,
  lFilename ,             
  lFullFileName : String;
  lFileData : TStream;

  lParameters : TStringlist;

  lRetval : TRtcValue;

  lBOSession :  TBOSessionData;

  lExternal : TBOImportData_External;
  lImportinfo : TBOImportExternalDataInfoOptions;

begin
   lParameters := TStringlist.Create;
   lParameters.Delimiter := ',';
   lParameters.StrictDelimiter := True;
   try
      try
        lAction                   := Param.AsString['Action'];
        lParameters.DelimitedText := Param.asString['Parameters'];
        lFilename                 := Param.asString['Filename'];
        lFileData                 := Param.asByteStream['FileData'];


        lBOSession := TBOSessionData( TrtcDataServer( Sender ).Session.Obj['SessionData']);

        if lAction = 'Funcionários' then begin
           lExternal := TBOImportData_External.Create( lBOSession );
           try
             lImportinfo := [];
             if lParameters.Values['Unidades']     = '1' then lImportinfo := lImportInfo + [ diUnidades ];
             if lParameters.Values['Cargos']       = '1' then lImportinfo := lImportInfo + [ diCargos ];
             if lParameters.Values['Funcionarios'] = '1' then lImportinfo := lImportInfo + [ diFuncionarios ];
             lExternal.ImportInfo := lImportInfo;
             lFileData.Position := 0;
             lExternal.PrepareFileName(lFileName, lFileData, lFullFileName );
             lExternal.FileName := lFullFileName;
             with Result.NewRecord do begin
                  asBoolean['Success'] := lExternal.Execute; #2
                  asString['Log'] := lExternal.LogData.ToString;
             end;
           finally
             lExternal.Free;
           end;
        end;
      except
        on e:exception do begin
             with Result.NewRecord do begin
                  asBoolean['Success'] := False;
                  asString['Log'] := lExternal.LogData.ToString;
             end;
        end;

      end;
   finally
      lParameters.Free;
   end;
end;

#2 might take some time to process. Upon success it will return True. This routine should take between 5 to 10 minutes to complete.

The problem is that after exact 30s the following error is raised:
   Error: Connection problems, no response received

This application is responsive for 30s before the error is raised. (I can move the modal window).

On the server side, the call should get call on a separated thread right?
Is there something wrong with this implementation? The problem is on the server side?
Do I need to check for active thread?
I'm a bit lost, any tips would help a lot.

TIA,
Clément


Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: April 12, 2015, 06:27:57 AM »

When there is zero traffic going in either way (while the Server is working), chances are high that a Router, Proxy or Client will terminate the connection, thinking that the Server is gone. The AutoSessionsPing property won't help you here, because it can only send a request to the Server when the connection is NOT in use, but when you have already sent out a request and are waiting for a response from the Server, there will be absolutely no traffic until the Server starts sending a response back. 30 seconds does sound like a default Timeout value used by Socket APIs, as well as most HTTP Proxies, with the goal to drop connections which are idle for longer periods of time and presumed to be dead.

Generally speaking, RTC remote functions are not designed for executing very long processing tasks on the Server, and 5 to 10 minutes is an extremely long time period for an HTTP connection to be without any traffic. You could try setting TimeoutsOfAPI properties (especially the SendTimeout and ReceiveTimeout) on the TRtcHttpClient and TRtcHttpServer components to high enough values, for example 20 minutes (=1200 seconds, since all Timeout values are in seconds), which might help avoid getting your connection closed by the Socket API when the Server is working, but there is no guarantee this would work, because there are other factors (like routers and proxy servers) which could also decide to simply drop the connection if there is no traffic going in either way.

TRtcHttpGateClient and TRtcGateway components solve this problem (connections being dropped when there is no useful traffic) by using two asynchronous connections (one for sending, one for receiving data) and sending periodic PING messages in both ways when there is no other traffic. This can keep the connetions alive infinitely. But when you are using and single connection over HTTP, this is not possible, so ... unless changing TimeoutsOfAPI properties helps remedy your problem, you will need to find another way to execute that long running function on the Server and prepare the result, which would not require a connection to remain open without any traffic for 5 to 10 minutes.

Best Regards,
Danijel Tkalcec
Logged
ClementDoss
RTC License
***
Posts: 36


« Reply #2 on: April 13, 2015, 05:14:46 PM »

Hi Danijel,

Thanks for taking your time to give such a detailed explanation.



Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 17 queries.