Danijel,
I'm making progress in learning the ins and outs of RTC. I absolutely love the flexibility you provide in passing parameters/results in remote functions. I have a couple of specialized servers I've written using Indy that I'm thinking about converting over to RTC. Both run as a service and basically accept ASCII commands along with parameters and then do some action and send data back, much like an FTP server would.
Programming was pretty easy with the blocking style of Indy and I'm comfortable with that. With RTC, the server side of things is very easy as well, since everything is pretty much received asynchronously. It fits well in the event driven model. However, I'm trying to get my thoughts on the best way to handle the client in the event driven model.
My client piece runs a series of tasks that need to be run in a certain order and need to ensure it completes successfully before I proceed to the next step. Here's one idea. Basically have an event that I reset before calling the remote function. I then do a WaitFor on that event, which will be signaled in the OnReturn event for the function I just called. In my WaitFor logic, I set a 50ms timeout value. If I timeout I process messages to keep things running and then return to my Event.WaitFor. I exit out of that loop only if the event is signaled, errors out or abandoned.
Here's a snippet that shows my basic concept.
for i:=0 to Tasks.Count-1 do
begin
ResultDone.ResetEvent;
with RtcClientModule1 do
begin
with Data.NewFunction(Tasks[i].FunctionName) do
begin
asString['SomeParameter'] := Tasks[i].Params[i];
Call(RtcResult1);
end;
end;
repeat
WRes := ResultDone.WaitFor(50);
case WRes of
wr_Abandoned,wr_Error : Break;
wr_Timeout:
begin
Application.ProcessMessages;
end;
end;
until WRes in [wr_Abandoned,wr_Error,wr_Signaled];
end;
procedure TForm1.RtcResult1Return(Sender: TRtcConnection; Data,
Result: TRtcValue);
var
i : Integer;
S : String;
begin
// do something with the result
ResultDone.SetEvent;
end;
I suppose another way to do this would be to keep a state machine counter and then in the OnReturn event increment the counter and post a message to some procedure that calls that particular task.
Anyway, I was wondering what your thoughts are on this type of programming issue.
Thanks for any input,
Gary Bell