WAMP 1.0 è un sottoprotocollo aperto di WebSocket che fornisce due pattern di messaggistica asincrona: RPC e PubSub.
Da sgcWebSockets 4.3.8 è supportato un nuovo metodo, non incluso nella specifica WAMP 1.0, ma molto utile per i nostri utenti. WAMP consente chiamate RPC, ma la risposta del server può essere solo riuscita o fallita. A volte un'RPC richiede più di un risultato (streaming di notizie, quotazioni, mostrare l'avanzamento...) e qui la specifica non lo permette (WAMP 2.0 lo consente, ma è molto più complesso).
Quindi, da sgcWebSockets 4.3.8, è disponibile l'RPC con risultati multipli.
Funziona sostanzialmente come l'RPC precedente, ma c'è un nuovo evento lato client chiamato OnCallProgressResult che viene generato se il server invia un risultato parziale e ci sono ancora altri risultati da ricevere. Contemporaneamente, il server ha un nuovo metodo chiamato CallProgressResult, che viene chiamato per inviare un risultato parziale al client.
Il client può annullare una chiamata RPC attiva usando il nuovo metodo CancelCall e passando CallId come parametro.
Esempio 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;
Esempio client
procedure OnCallResultClient(Connection: TsgcWSConnection; CallId, Result: string);
begin
// This is the last result
ShowMessage(Result);
end;
procedure OnCallProgressResultClient(Connection: TsgcWSConnection; CallId, Result: string);
begin
// Partial result, there are still more results to receive
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('GetProgressiveTime');
