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

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Lesson 4 - sending a large file that needs to be created first  (Read 4291 times)
mthand
RTC Expired
*
Posts: 17


« on: April 08, 2013, 10:05:29 PM »

I am working with lesson 4 regarding "Sending large files out" and it works great - with one small problem.
When the file is a test file that already exists, it's fine.

But now that I have that part working, what I really need is to create a file (based on the GET query parameters), then create an HTML file which I then want to send.  That might take 4 or 5 seconds.  But the CheckRequest at the point of the Accept immediately looks for the file, to set ContentLength, which in this case is -1.

So my question is what is the procedure to handle the CheckRequest and OnDataReceived when there will be a delay in order to first create the file I want to send ?

Thanks for any help.  All in all I'm extremely happy with what i can accomplish with these tools.
-John
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: April 12, 2013, 01:35:02 PM »

If it is a GET request with no content body (all the parameters are inside the HTTP header), then you can create the file directly inside the OnCheckRequest event before calling "Accept" and before calling Write or WriteHeader.

If it is a POST request, where you also need to process the request content body before you can create the file for your response, you should only call the "Accept" method from the OnCheckRequest event, but you should NOT call Write nor WriteHeader from OnCheckRequest. You should then implement the OnDataReceived event to receive the complete request content (for example, by using "if TRtcDataServer(Server).Request.Complete then ..."), read the content body, prepare the file you want to send, and start sending the file from the same OnDataReceived event. To continue sending the file out, simply use the OnDataSent event as shown in the Server Lesson 4.

Best Regards,
Danijel Tkalcec
Logged
mthand
RTC Expired
*
Posts: 17


« Reply #2 on: April 14, 2013, 11:36:42 AM »

Ok, I understand.  In my case I ended up delaying in the CheckRequest before the Accept, but I'll take a look at the other option too.
Thanks
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 17 queries.