Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
satish #1
Member since Jul 2013 · 4 posts · Location: india
Group memberships: Members
Show profile · Link to this post
Subject: What is RPC mechanism in Matrix?
Hi,

We are writing an app in which 2 people can run the same (desktop) app and share the effects of events with each other.
 we require the effect of an event (using method call ) on one user's machine getting exactly replicated in buddy's app.

We plan to get it thru xmpp-rpc. => catch the event on ones machine, call a method() as part of event's trigger, send this method/call to be executed on buddy's machine using xmpp-rpc.

We did the following: Pl. let us know if this approach is right. Also we are unable to map the same to Matrix impl as the packages seem much diff. If u have any inputs, appreciate that...


  1. var clientJID = new agsXMPP.Jid("abc@gmail.com");
  2.  
  3. agsXMPP.XmppClientConnection con = new agsXMPP.XmppClientConnection("gmail.com");
  4.  con.Open("username", "password");
  5.  
  6. //... on login event, authenticat
  7. var iq = new agsXMPP.protocol.iq.rpc.RpcIq(IqType.set, clientJID);
  8. System.Collections.ArrayList param = new System.Collections.ArrayList();
  9.  
  10. //this is one event parameter
  11. param.Add("parameter");
  12.  
  13. iq.Query.MethodCall = new agsXMPP.protocol.iq.rpc.MethodCall(<class-name>.<method-name>, param);
  14.                    
  15. IQ result = con.IqGrabber.SendIq(iq, 5000);

When we specify the RPC method call (like the one below), where do u specify the class name  of the method that should be executed?(in matrix)
 
Any help is greatly appreciated

Thanks
Satish
This post was edited on 2013-07-11, 14:30 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
when you post me the XML of the RPC code you want to execute, or the function name and the parameters I can post the required codes for MatriX here.

Xml-RPC is a old and very limited protocol. Normally you use this in XMPP only when you have to forward the calls to existing Xml-RPC code or services. Using it for a new implementation on both sides for remote controlling makes no sense to me, because we have much better extensions in XMPP which you can use. Or you can write your own extensions very easy.

Alex
Avatar
satish #3
Member since Jul 2013 · 4 posts · Location: india
Group memberships: Members
Show profile · Link to this post
Thanks Alex,

 We will evaluate this XEP-0050. But we have already a legacy code in xmpp rpc using in my application. We want to re-write this with help Matrix XMPP.

Can you send any example related Matrix-XMPP-RPC.


Satish
Avatar
Alex #4
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by satish:
Can you send any example related Matrix-XMPP-RPC.

as I said before, let me know the function name and the parameters and I will post you the code for MatriX.
Or post a the XMPP XML for an existing RPC call from your debug and I will post the required codes here.
This post was edited on 2013-07-11, 15:23 by Alex.
Avatar
satish #5
Member since Jul 2013 · 4 posts · Location: india
Group memberships: Members
Show profile · Link to this post
Thanks Alex,

See my legacy rpc code in http://pastebin.com/dFUbquaG



satish
Avatar
Alex #6
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
here is a code snippet which builds the first rpc iq in your logs:

  1. var iq = new RpcIq
  2.     {
  3.         Id = "4jLvG-34", // not required because MatriX automatically adds a unique Id
  4.         To = "buyer@collabnexgen.net/Smack",
  5.         From = "seller@collabnexgen.net/Smack", // from also not required, the server adds this automatically
  6.         Type = Matrix.Xmpp.IqType.set
  7.     };
  8.  
  9. var call = new MethodCall { MethodName = "com.collabng.net.remoteable.ViewpointRemoteable.setViewpoint" };
  10.  
  11. var parameters = new Parameters
  12.     {
  13.         "viewpoint_BackView_collabng"
  14.     };
  15. call.SetParameters(parameters);
  16. iq.Rpc.MethodCall = call;
  17.  
  18. Console.WriteLine(iq.Tostring());
Avatar
satish #7
Member since Jul 2013 · 4 posts · Location: india
Group memberships: Members
Show profile · Link to this post
thanks Alex.. it works

satish
Avatar
rktumuluri #8
Member since Jul 2013 · 1 post
Group memberships: Members
Show profile · Link to this post
In reply to post #6
Subject: sample with request/response ...
Alex,

 Is it possible to provide a simple  sample for jabber-rpc using Matrix ?. (request, response, error ?) . I am trying to put together a sample. Am using the weather sample. It's just not intuitive. Some of the classes/concepts are fuzzy.

/rk
Avatar
Alex #9
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Ok, lets try to use Rpc for the weather example. We want to request the weather for a postcode over Rpc with an Iq. The iq will look like the following.
GetTemperature is our methodName, and we pass one integer parameter which is our postcode (74080).

  1. <iq id="MX_1" to="user@server.com/MatriX" type="set" xmlns="jabber:client">
  2.  <query xmlns="jabber:iq:rpc">
  3.     <methodCall>
  4.       <methodName>GetTemperature</methodName>
  5.       <params>
  6.         <param>
  7.           <value>
  8.             <i4>74080</i4>
  9.           </value>
  10.         </param>
  11.       </params>
  12.     </methodCall>
  13.  </query>
  14. </iq>

The following code builds this Rpc request.

  1. var iq = new RpcIq
  2. {
  3.     To = "user@server.com/MatriX",
  4.     Type = Matrix.Xmpp.IqType.set
  5. };
  6.  
  7. var call = new MethodCall { MethodName = "GetTemperature" };
  8. var parameters = new Parameters
  9.     {
  10.         74080
  11.     };
  12.  
  13. call.SetParameters(parameters);
  14. iq.Rpc.MethodCall = call;

on client 2 this comes in the OnIq handler. There we check whether this is an Rpc call an then read the methodName and the params.

  1. private void xmppClient_OnIq(object sender, IqEventArgs e)
  2. {
  3.     if (e.Iq.Query is Matrix.Xmpp.Rpc.Rpc)
  4.     {
  5.         var rpc = e.Iq.Query as Matrix.Xmpp.Rpc.Rpc;
  6.         var methodCall = rpc.MethodCall;
  7.         if (methodCall != null)
  8.         {
  9.             // here you read the methodname and the params
  10.             var methodName = methodCall.MethodName;
  11.             var pars = methodCall.GetParameters();
  12.             int postcode = (int) pars[0];
  13.         }
  14.     }
  15. }

now client 2 has the method name and teh params. So it can lookup the temperature for postcode 74080 and send back teh response.
The response XML looks like this:

  1. <iq id="MX_1" type="result" xmlns="jabber:client" to='user@server.com/MatriX'>
  2.  <query xmlns="jabber:iq:rpc">
  3.     <methodResponse>
  4.       <params>
  5.         <param>
  6.           <value>
  7.             <i4>80</i4>
  8.           </value>
  9.         </param>
  10.       </params>
  11.     </methodResponse>
  12.  </query>
  13. </iq>

the following code creates this Iq.

  1. var resIq = new RpcIq
  2. {
  3.     Id = iq.Id, // must use th id of the request
  4.     To = iq.From,
  5.     Type = Matrix.Xmpp.IqType.result // or return error
  6. };
  7.  
  8. var resp = new MethodResponse();
  9.  
  10. var parameters = new Parameters
  11.     {
  12.         80
  13.     };
  14.  
  15. resp.SetParameters(parameters);
  16. resIq.Rpc.MethodResponse = resp;

the last step is readin the respone on client 1 which gets done by the following code:

  1. private void TemperatureResponse(object sender, IqEventArgs e)
  2. {
  3.     if (e.Iq.Query is Matrix.Xmpp.Rpc.Rpc)
  4.     {
  5.         var rpc = e.Iq.Query as Matrix.Xmpp.Rpc.Rpc;
  6.         var methodResp = rpc.MethodResponse;
  7.         if (methodResp != null)
  8.         {
  9.             // here you read the methodname and the params
  10.             var pars = methodResp.GetParameters();
  11.             int temp = (int)pars[0];
  12.         }
  13.     }
  14. }
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS