Title: Works fine on windows but not on android. Post by: LeonidasP on February 06, 2017, 09:48:00 PM Hi!
Below is the code for the onDataReceived of a trtcDataRequest component that receives data from an WebServer. The behavior like this : The on hcRequestDataReceived event is fired only once. When it is fired the trace shows that dataClient.Response.Done is false. The event that seems to follow the execution of hcRequestDataReceive is the onDisconnect event of the corresponding TrtcHttpClient. I tried to catch any exceptions but ... Something closes the connection but I cannot understand what. The exact same code works fine under windows 10. Here are some of the properties of the trtcHttpClient HC.ReconnectOn.ConnectLost:= True; HC.ReconnectOn.ConnectFail:= True; HC.ReconnectOn.ConnectError:= True; rtcFMX.GUI is included in the uses clause as it should be. I have tried it multiThreaded and not multiThreaded the behavior is the same. procedure TmainForm.hcRequestDataReceived(Sender: TRtcConnection); var rx: RtcByteArray; dataClient : TRtcDataClient; begin if not sender.inMainThread then Begin sender.Sync(HcRequestDataReceived); exit; End; dataClient:=TRtcDataClient(Sender); rx:= dataClient.readEx; if length(rx)<>0 then Begin //store the data End; if dataClient.Response.Done then Begin // do something with the data End; end; Any help would be appreciated! Thanks. Title: Re: Works fine on windows but not on android. Post by: D.Tkalcec (RTC) on February 07, 2017, 08:46:53 AM I either need an example Project to test it locally (full source code), or more detailed information.
If you can not provide an example Project (send it to me by E-Mail), please answer the following questions: 1. How are TRtcHttpClient and TRtcDataRequest components configured? I need a complete list of all properties on both components. 2. Which events are implemented on TRtcHttpClient and TRtcDataRequest components? Please, also provide the code you are using to prepare and post your request (called from the Main Thread?), and the code you have in your TRtcDataRequest's OnBeginRequest event. 3. Which RTC SDK version are you using? If you are NOT using the latest RTC SDK update, please download it and try again. 4. Which Delphi version are you using? 5. How does your Windows PC and how does your Android device connect to the WebServer? 6. Is the WebServer built in Delphi using the RTC SDK, or is it a 3rd-party WebServer? Best Regards, Danijel Tkalcec Title: Re: Works fine on windows but not on android. Post by: LeonidasP on February 07, 2017, 11:17:17 AM Hi Danijel!.
My current SDK version is v7.74 (2017.Q1). I will first try with SDK V7.77 and I 'll make another post with the results. Thanks for the quick reply! Leonidas. Title: Re: Works fine on windows but not on android. Post by: LeonidasP on February 07, 2017, 11:59:24 AM Hi again!
Installed v7.77 and the problem is still there. Code has been sent by E-Mail. Here are some more data.. WebServer is 3rd-party. Delphi version is 10.1 Berlin. Both Pc and Android device use LAN connection to connect to WebServer.(also tried WAN connection with the same results). Leonidas. Title: Re: Works fine on windows but not on android. Post by: D.Tkalcec (RTC) on February 07, 2017, 06:50:44 PM I wasn't able to test your Project, because your Server is unreachable. But I did find some problems with your code, which might explain why it works for you on Windows but not on Android:
1. You have "Application.ProcessMessages" in a few RTC events. You should NEVER call Application.ProcessMessages from any RTC event or any code which might end up being executed as a result of a RTC event. 2. You are using the "UserLogin" property on the TRtcHttpClient component, which is available ONLY on Windows (it requires the WinInet or WinHTTP API). If you want your App to be cross-platform, you have to manually handle User Authentication on the Server. Check the HTTP specification about Basic Authentication for details. 3. You are using the "Timeout" property to disconnect the Client after 3 seconds in a multi-threaded environment, or 1 second in a single-threaded environment. That is way too short. You need to take into account possible network slow-downs and avoid using timeouts shorter than 10 seconds if your App should run over the Internet. I hope that helps. Best Regards, Danijel Tkalcec Title: Re: Works fine on windows but not on android. Post by: LeonidasP on February 07, 2017, 07:22:41 PM Thanks for the reply!.
No.1:Application.processMessages was there under if not hc.MultiThreaded then ... so when code execution was multiThreaded non of the "Application.processMessages" was executed. (I just had to try that too! ;D) No.3: HC.Timeout.AfterConnecting small values I don't think is the problem because tests are made in my LAN.(Used to be bigger some coding ago!) "avoid using timeouts shorter than 10 seconds if your App should run over the Internet" is a very good advice though.Thank you for that. So I have the feeling that my problem has to do with No.2 I 'll give it a try and come back. Thanks a lot. Title: Re: Works fine on windows but not on android. Post by: D.Tkalcec (RTC) on February 07, 2017, 07:50:10 PM OK. You might also want to update your RTC SDK version to v7.78 (if you haven't done so already) and take a look at the new "fmx4File_Client.dpr" Project in the "Demos/File_Client" folder. It is a very minimalistic, but fully cross-platform HTTP Client example, which can be used to post a request to any HTTP Server and get the response, while logging all events triggered by RTC components in a Memo. If you add basic authentication to Request Headers, it should also be working with your Server.
Best Regards, Danijel Tkalcec Title: Re: Works fine on windows but not on android. Post by: LeonidasP on February 07, 2017, 11:19:58 PM Hi again!
Eventually the problem was No.2. Basic Authentication. Had to use a separate trtcDataRequest Component (for the implementation of the authentication procedure) with HeaderText:='Authorization: Basic '+EncodeString('username:password'); (doesn't look very pretty but does the job). and fileName :='/'; (very important). Thanks a lot. LeonidasP. Title: Re: Works fine on windows but not on android. Post by: D.Tkalcec (RTC) on February 08, 2017, 03:20:46 AM Perfect. Thanks for your feedback.
Best Regards, Danijel Tkalcec |