Products

Price/Order

Support

Partners

Testimonials

Test Results

About us

Contact
 TRtcDataClient.Read function can be called only once.
Bottom
 
Total posts: 3
 Author TRtcDataClient.Read function can be called only once.
Johann Campbell

08.05.2008 18:02:34
Registered user
Hi, I've something peculiar this morning. When I call the Read method of a TRtcDataClient, the first call gets the content however subsequent calls return nothing. Is this normal behavior for this component?

Thanks,

Johann.
Danijel Tkalcec [RTC]

08.05.2008 19:23:49
Registered user
Yes, this is normal and expected behavior.

A call to the Read method will give you all data currently in the receiving buffer and clear the buffer, so that the next call will not return anything until more data is received. This behavior also allows you to keep the buffer filling up by not using the Read method, and then get the whole received content at once without having to use intermediate storage.

In other words, you can do something like (OnDataReceived event) ...

if TRtcDataClient(Sender).Response.Done=FALSE then
  begin
  // As long as we do not call READ here, all received data will stay
  // in the buffer and we will get the complete content when "Response.Done=TRUE".
  end
else
  begin
  // Since we did not make a single call to READ as data was coming in,
  // we will now get the complete response content with a single READ call.
  MyWholeResponse:=TRtcDataClient(Sender).Read;

  // Calling READ here is not necessary if you do not need the content,
  // since the request and response objects will automatically be destroyed
  // and receiving buffer cleared when the request/response loop is over.
  end;

Best Regards,
Danijel Tkalcec
Johann Campbell

08.05.2008 20:54:27
Registered user
Ok great. Thanks for the explanation.