Title: Posting data to website (moving from v2.7 to v2010.q2 build 383) Post by: SevenOut on June 11, 2010, 08:13:11 PM I have a project that I had been using RTC v2.7 and was working fine. There are only 2 components being used: TRtcHttpClient and TRtcDataRequest. Below is the code for the events I use.
Code: procedure TForm6.Button2Click(Sender: TObject); First question/problem: After upgrading to v2010.q2 build 383 the code no longer works as before. I am getting to the DataReceived event but the call to Read is not returning anything just an empty string. I'm sure this has something to do with a change that was made somewhere along the way between 2.7 and 2010.q2. I'm hoping that someone can help me out here. Second question/problem: The reason I upgraded to 2010.q2 was because I now need this to be a blocking call. I need to be able to post my request to the server and wait for a response without going through a separate event to get the response. Any help here would be greatly appreciated. Thanks Scott Title: Re: Posting data to website (moving from v2.7 to v2010.q2 build 383) Post by: D.Tkalcec (RTC) on June 11, 2010, 08:29:04 PM I see two things which could be the reason for your problem:
1) Are you setting RtcHttpClient1.ServerPort? I don't see it anywhere. 2) Calling "Disconnect" before using "Read" in the OnDataReceived event is simply wrong. If you want to close the connection but expect to be able to read from it, first call Read and then call Disconnect. Doing it the other way around might have been working before, but if it did then it was a glitch in the old RTC SDK version. Best Regards, Danijel Tkalcec Title: Re: Posting data to website (moving from v2.7 to v2010.q2 build 383) Post by: D.Tkalcec (RTC) on June 11, 2010, 08:34:18 PM As for your 2nd question, the latest RTC SDK version has support for making blocking remote function calls without implementing any events.
But ... if you need to post a request with custom data to the Server (using a TRtcDataRequest component), you can only wait for the Response from the Server by using the WaitForCompletion method (as before), but you still need to implement events to write the request out and to read the data received in the response. Best Regards, Danijel Tkalcec Title: Re: Posting data to website (moving from v2.7 to v2010.q2 build 383) Post by: SevenOut on June 11, 2010, 09:08:56 PM I see two things which could be the reason for your problem: I'm using port 80. After posting this question I did notice that I was disconnecting before reading and I switched those lines and it started working again.1) Are you setting RtcHttpClient1.ServerPort? I don't see it anywhere. 2) Calling "Disconnect" before using "Read" in the OnDataReceived event is simply wrong. If you want to close the connection but expect to be able to read from it, first call Read and then call Disconnect. Doing it the other way around might have been working before, but if it did then it was a glitch in the old RTC SDK version. Best Regards, Danijel Tkalcec Thanks, Scott Title: Re: Posting data to website (moving from v2.7 to v2010.q2 build 383) Post by: SevenOut on June 11, 2010, 09:17:19 PM As for your 2nd question, the latest RTC SDK version has support for making blocking remote function calls without implementing any events. But ... if you need to post a request with custom data to the Server (using a TRtcDataRequest component), you can only wait for the Response from the Server by using the WaitForCompletion method (as before), but you still need to implement events to write the request out and to read the data received in the response. Best Regards, Danijel Tkalcec Are there any demos or sample code that outline this? What I would really like to be able to do is this: Code: begin some procedure in my code; So you are saying that there is currently no way with RTC to do this without relying on a separate event to be fired to read the response? Thanks, Scott Title: Re: Posting data to website (moving from v2.7 to v2010.q2 build 383) Post by: D.Tkalcec (RTC) on June 11, 2010, 09:32:48 PM So you are saying that there is currently no way with RTC to do this without relying on a separate event to be fired to read the response? Correct. If you want to post a custom request to the Server which will give you back a custom Response, you can only do it by implementing the OnCheckRequest and OnDataReceived events, just like you've done in the code you have posted above.If you want to wait for a response after you have Posted a Request, use the "WaitForCompletion", "DoWaitForCompletion" or "WaitForCompletionEx" methods, which are available on TRtcDataRequest and TRtcDataClient components. For example, the following line will wait 60 seconds for a response to be received from the Server without allowing user interaction. If something goes wrong or the response does not arrive within 60 seconds, an exception will be raised (depending on what goes wrong) ... RtcDataRequest1.WaitForCompletionEx(False, 60); Best Regards, Danijel Tkalcec Title: Re: Posting data to website (moving from v2.7 to v2010.q2 build 383) Post by: SevenOut on June 11, 2010, 10:21:17 PM Correct. If you want to post a custom request to the Server which will give you back a custom Response, you can only do it by implementing the OnCheckRequest and OnDataReceived events, just like you've done in the code you have posted above. Okay... I'll see if I can modify things to make it work. I would be helpful to have some way to simply post data to a server and get a response without requiring events to be called. I think I read in another thread that you might be working on this. Thanks, Scott Title: Re: Posting data to website (moving from v2.7 to v2010.q2 build 383) Post by: D.Tkalcec (RTC) on June 11, 2010, 10:33:55 PM I am planning to add methods for posting short requests and receive short responses in a blocking way without implementing any events, but it is not one of my priorities and there are a lot of other things on my to-do list as well, so there is no deadline for when this feature will be released. If you find this feature very important, please start a POLL in the "Wish List" Forum section.
Best Regards, Danijel Tkalcec |