RTC Forums
November 23, 2024, 09:35:26 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: HTTP Server JSON for Android application  (Read 4383 times)
ISIGest
RTC Expired
*
Posts: 121


« on: September 03, 2016, 10:55:39 AM »

I want to develop an applciation with Android Studio and have my server with TRtcHttpServer in a delphi application.
Now I've a problem with client requests.
I use TRtcDataProvider to handle http request and send data to android application when needed.
My problem is when I need from client a big data (readed from database on server) converted to JSON, this operation could be long about 30/40 seconds.
Now what is the best way to comunicate with client, now I do this:

in OnCheckRequest

1. check the header and url for client request
2.
Code:
myServer.Accept;
myServer.Response.ContentType := 'application/json';
myServer.Response.ContentLength := 0; <---- HERE IS MY FIRST PROBLEM: I don't know the [b]content-length[/b] becase the query is not executed

in OnDataSent
1. Execute needed database query
2. Convert the result as JSON
3. Write the data to client.

Is this the best way to do my work?
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: September 07, 2016, 07:46:03 AM »

1. If you can send the complete content from a single OnCheckRequest or OnDataReceived event by using the Write or WriteEx method, there is no need to manually set the Content Length.

2. From the OnCheckRequest event, you only have to call the Accept method. You can read the request content (using the Read or ReadEx method), prepare response headers and write the content out (using Write or WriteEx) from the OnDataReceived event.

3. You only need the OnDataSent event if you are sending the content in pieces. Since you will be sending the complete JSON response in from a single RTC event (OnDataReiceved), OnDataSent event does NOT have to be implemented.

If you need more info, check Server Lessons from the Quick Start guide or take a look at ServerLesson sub-folders in the QuickStart folder (included in the RTC SDK zip file).

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.023 seconds with 16 queries.