RTC Forums
November 24, 2024, 04:25:51 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Event OnException or OnConnectError not fired in iOS  (Read 5571 times)
Christen
RTC Expired
*
Posts: 9


« on: August 08, 2012, 08:21:54 AM »

I´m trying to catch errors while connecting to a server in iOS with a TRtcHttpClient. Events OnException or OnConnectError are not fired with connection errors (bad url, bad port, server not working, etc.).
How can I catch those situations in iOS?

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


« Reply #1 on: August 08, 2012, 04:03:29 PM »

I can't reproduce this here. When I use the latest RTC SDK version with the File_Client demo on iOS, the OnConnectError event gets fired if there are connection errors.

1. Which RTC SDK version are you using?
2. Which FreePascal version are you using?
3. Are you using the "rtcFMX_GUI" unit in your Project?
4. How is the TRtcHttpClient component set up (please list all property values)?
5. How is the OnConnectError event implemented (please post the compolete event code)?
6. Do you see the same behavior in the iOS Simulator and in the iOS device?

Best Regards,
Danijel Tkalcec
Logged
Christen
RTC Expired
*
Posts: 9


« Reply #2 on: August 09, 2012, 07:25:13 AM »

I'm using RTC SDK version 5.11
FreePascal version 2.6.0
The rtcFMX_GUI unit is included in theproject.

I'm using the TRtcHttpClient in the following config:

  object RtcHttpClient: TRtcHttpClient
    MultiThreaded = True
    ServerAddr = 'www.myserver.com'
    ServerPort = '80'
    OnException = RtcHttpClientException
    OnConnectFail = RtcHttpClientConnectFail
    OnConnectError = RtcHttpClientConnectError
    AutoConnect = True
    UseProxy = True
    OnInvalidResponse = RtcHttpClientInvalidResponse
  end
  object RtcClientModule: TRtcClientModule
    AutoSyncEvents = True
    Client = RtcHttpClient
    ModuleHost = 'WWW.MYSERVER.COM'
    ModuleFileName = '/MyServer/MyServer.dll/Server'
  end
  object RtcResult: TRtcResult
    OnReturn = RtcResultReturn
  end

The code I use to call the server is the following:

  with RtcClientModule.Data.NewFunction('MyFunction') do
    asString['Data'] := MyData;
  RtcClientModule.Call(RtcResultReturn);

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


« Reply #3 on: August 09, 2012, 07:31:45 AM »

You wrote that the "OnConnectError" event isn't firing if the Client can't connect to the Server, so I will also need to see the code of your "OnConnectError" event. Thank you.

NOTE: The "OnConnectError" event is ONLY fired if a connection to the Server can't get established (Server not listening, DNS problems or wrong Port number). If you do connected to a Server (or a Proxy), but then the connection breaks or you get the wrong response, the "OnConnectError" event won't fire (it is not supposed to). The "OnConnectLost" event would fire if a connection was lost before a response was received, but in case you are connected to the wrong Server, you could also get a full (but wrong) response, so the OnConnectLost event wouldn't fire either.

This is why TRtcClientModule and TRtcResult components have their own events for handling errors caused by "bad data". To make sure you have all the communication errors covered when working with remote functions using the TRtcClientModule component, including disconnects, attempts to communicate with the wrong Server, or working with a bad Proxy, you should implement the RequestAborted event on each TRtcResult component, or the OnResponseAbort event on the TRtcClientModule component. These events provide you with the most reliable way to get notified if your remote call gets aborted.

For more detailed information about the reason for an aborted remote call, you might also want to implement OnEncryptNotSupported, OnEncryptRequired, OnEncryptWrongKey, OnResponseError, OnResponseReject and OnResultError events on the TRtcClientModule component.

Also ... because you are working with iOS Clients, your communication will be going through Proxy Servers used by various mobile providers, and some of them won't handle request forwarding correctly and your Server will receive a complete URL in each request because of an URI. To fix this problem, you should set the "FixupRequest.RemovePrefix" property on the TRtcHttpServer component to TRUE (in your Server). Otherwise, remote function calls coming from your iOS Clients won't reach the TRtcServerModule in your Server and will get a "bad request" response.

Best Regards,
Danijel Tkalcec
Logged
Christen
RTC Expired
*
Posts: 9


« Reply #4 on: August 09, 2012, 08:30:08 AM »

I've updated to latest stable release (5.17) with same results.

The OnConnectError event only logs the error:

procedure TdatPurchaseLicense.RtcHttpClientConnectError(Sender: TRtcConnection;
  E: Exception);
begin
  LogError(E.Message);
end;

This event should fire when I shut down the server (or changing the port number in the client). In fact it fires in windows but not in iOS.

Best regards
Logged
Christen
RTC Expired
*
Posts: 9


« Reply #5 on: August 09, 2012, 08:48:14 AM »

I've found the cause of the problem.
The event OnConnectError doesn't fire in the main thread and the interface is not correctly updated. The solution is to call a synchronized event.
It would be nice to have a AutoSyncEvents propery in TRtcHttpClient similar to the existing property in TRtcClientModule.

Thank you for your advice it has been helphul regarding to the events related to errors in a communication.

Best regards

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


« Reply #6 on: August 09, 2012, 10:33:50 AM »

Thank you for your feedback. I'm glad to know the problem is solved.

TRtcHttpClient and TRtcHttpServer components don't have the "AutoSyncEvents" property, because their events usually don't require GUI access (used for logging). For events triggered on connection components which do require GUI access, you should use the "Sender.inMainThread" method to check if the event is executed in the Main Thread. And if NOT, use the "Sender.Sync()" method to synchronize the event with the Main Thread. For example, like this:
Code:
procedure TMainForm.MyClientConnectError(Sender:TRtcConnection);
  begin
  if not Sender.inMainThread then
    begin
    Sender.Sync(MyClientConnectError);
    Exit;
    end;
  // Here comes your code which requires GUI access ...
  end;

Best Regards,
Danijel Tkalcec
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.026 seconds with 16 queries.