RTC Forums
May 05, 2024, 05:55:47 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Posting data to website (moving from v2.7 to v2010.q2 build 383)  (Read 5128 times)
SevenOut
RTC Expired
*
Posts: 24


« 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);
var
   Data: String;
   iRequest: String;
begin
   iRequest := 'Some Sample Data Here';
   Data := iRequest + #10;

   RtcHttpClient1.UseSSL := True;
   RtcHttpClient1.MultiThreaded := True;
   RtcHttpClient1.ServerAddr := 'activate.globalei.com';
   RtcHttpClient1.Connect;

   with RtcDataRequest1 do
   begin
      AutoSyncEvents := True;
      Request.Host := 'activate.globalei.com';
      Request.Method := 'POST';
      Request.Agent := 'GlobalEI IBMS/' + '1.0.0.10';
      Request.ContentType := 'application/x-www-form-urlencoded';
      Request.Params['DATA'] := Data;
      Post;
   end;
end;

procedure TForm6.RtcDataRequest1BeginRequest(Sender: TRtcConnection);
begin
   TRtcDataClient(Sender).Write(TRtcDataClient(Sender).Request.Params.Text);
end;

procedure TForm6.RtcDataRequest1DataReceived(Sender: TRtcConnection);
var
   Res: String;
begin
   with TRtcDataClient(Sender) do
   begin
      if Response.Done then
      begin
         RtcHttpClient1.Disconnect;
         Res := Read;
         Memo2.Lines.Clear;
         Memo2.Lines.Text := Res;
      end;
   end;
end;

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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #2 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
Logged
SevenOut
RTC Expired
*
Posts: 24


« Reply #3 on: June 11, 2010, 09:08:56 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
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.

Thanks,
Scott
Logged
SevenOut
RTC Expired
*
Posts: 24


« Reply #4 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;
execute some code;

Connect to Server;
Post data;
Wait for completion;
If not timeout then
   read and process response;
   disconnect;
else
   disconnect;
   show error;
end;

continue executing code;
end procedure;

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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #5 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
Logged
SevenOut
RTC Expired
*
Posts: 24


« Reply #6 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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #7 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
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.027 seconds with 16 queries.