WAMP 1.0 is an open WebSocket subprotocol that provides two asynchronous messaging patterns: RPC and PubSub.
From sgcWebSockets 4.3.8, a new method is supported, not included in WAMP 1.0 specification, but it can be very useful for our users. WAMP allows RPC calls, but server response can only be successful or not. Sometimes, an RPC requires more than one result (streaming news, quotes, show progress...) and here specification doesn't allow to do it (WAMP 2.0 it allows but is much more complex).
So, from sgcWebSockets 4.3.8, RPC with multiple results is available.
Basically it works equal than previous RPC, but there is a new Event in client side called OnCallProgressResult which is raised if server sends a partial result and there are still more results to be received. At the same time, server has a new method called CallProgressResult, which is called to send a partial result to client.
Client can cancel an active RPC call, using the new method CancelCall and passing CallId as parameter.
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;
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');
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.