RTC Forums

Subscription => Support => Topic started by: mthand on April 08, 2013, 10:05:29 PM



Title: Lesson 4 - sending a large file that needs to be created first
Post by: mthand 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


Title: Re: Lesson 4 - sending a large file that needs to be created first
Post by: D.Tkalcec (RTC) 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


Title: Re: Lesson 4 - sending a large file that needs to be created first
Post by: mthand 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