Sometimes, Remote Produce Calls require more than one result to finish requests, by default WAMP 1.0 protocol doesn't allow Partial results in a call, this is a feature only for sgcWebSockets library.
The flow is very similar to a simple RPC, but here there are 1 or more partial results before CallResult is called to finish the process.
Basically, a client requests a procedure to server and server can send a result or an error. If send a result, this can be the final result or it must send most results later. If it's final result, will call method CallResult and the process will be finished. If there are more results to send, will call method CallProgressResult.
Example: client requests server a method to receive every second the server time and stop after 20 messages.
WAMP Server
procedure OnServerCall(Connection: TsgcWSConnection; const CallId, ProcUri, Arguments: string);
var
vNum: Integer;
begin
if ProcUri = 'GetProgressiveTime' then
begin
vNum := StrToInt(Arguments);
for i := 1 to vNum do
begin
if i = 20 then
oServerWAMP.CallResult(CallId, FormatDateTime('yyyymmdd hh:nn:ss', Now))
else
oServerWAMP.CallProgressiveResult(CallId, FormatDateTime('yyyymmdd hh:nn:ss', Now));
end
end
else
oServer.WAMP.CallError(CallId, 'Unknown method');
end;
oServer := TsgcWebSocketServer.Create(nil);
oServer.Port := 80;
oServerWAMP := TsgcWSPServer_WAMP.Create(nil);
oServerWAMP.OnCall := OnServerCallEvent;
oServerWAMP.Server := oServer;
oServer.Active := True;
WAMP Client
procedure OnCallResultClient(Connection: TsgcWSConnection; CallId, Result: string);
begin
ShowMessage(Result);
end;
procedure OnCallProgressResultClient(Connection: TsgcWSConnection; CallId, Result: string);
begin
ShowMessage(Result);
end;
procedure OnCallErrorClient(Connection: TsgcWSConnection; const Error: string);
begin
ShowMessage(Error);
end;
oClient := TsgcWebSocketClient.Create(nil);
oClient.Host := '127.0.0.1';
oClient.Port := 80;
oClientWAMP := TsgcWSPClient_WAMP.Create(nil);
oClientWAMP.OnCallResult := OnCallResultClient;
oClientWAMP.OnCallProgressResult := OnCallProgressResultClient;
oClientWAMP.OnCallError := OnCallErrorClient;
oClientWAMP.Client := oClient;
oClient.Active := True;
// After client has connected, request GetTime from server
oClientWAMP.Call('GetProgressTime');