Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
atulloona #1
Member since Jun 2015 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: Send data to google xmpp server problem
Hello,

i am trying to send data from my server to google xmpp server, as per google doc.


Here is an XMPP stanza for a notification message:

  1. <message id="">
  2.  <gcm xmlns="google:mobile:data">
  3.   {
  4.       "to":"REGISTRATION_ID",  // "to" replaces "registration_ids"
  5.      "notification": {
  6.         "title": "Portugal vs. Denmark”,
  7.         "text”: "5 to 1”
  8.       },
  9.       "time_to_live":"600"
  10. }
  11.  
  12.   }
  13.  </gcm>
  14. </message>


how to map "to", "notification", "time_to_live" and other options...
 
using Matrix.Xmpp.Client.Message

 Message msg = new Matrix.Xmpp.Client.Message
            {
?
?
?
?
            };

            xmppClient.Send(msg);

please guide.

Thanks
Atul.
This post was edited 4 times, last on 2015-06-27, 19:19 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
see here how to create a custom packet class for the
  1. <gcm xmlns="google:mobile:data"/>
xml element.

http://www.ag-software.net/matrix-xmpp-sdk/matrix-develope…

once you have it then just do:

  1. var  gcm = new Gcm(); // GCM is your custom packet class
  2. gcm.Value = "The Jason payload";
  3.  
  4. var msg = new Message();
  5. msg.add(gcm);
Avatar
atulloona #3
Member since Jun 2015 · 6 posts
Group memberships: Members
Show profile · Link to this post
Managed to send what google gcm expects but getting following error.

  1. Message xmppmsg = new Matrix.Xmpp.Client.Message() { Type = MessageType.Normal };
  2. string json = @"{""to"":""cdcdcdcdcxxxxxxx"",
  3.            ""time_to_live"":""600"",
  4.            ""notification"":{
  5.                ""title"": ""Portugal vs. Denmark"",
  6.                ""text"": ""5 to 1""}
  7.         }";
  8.  
  9. XElement xElement;
  10. XName name = XName.Get("gcm", "google:mobile:data");
  11. xElement = new XElement(name);
  12.  
  13. xElement.Value = json;
  14.  
  15.  
  16. xmppmsg.Add(xElement);
  17.  
  18. xmppClient.Send(xmppmsg);
----------------------------------------------------------------------------------------------------------------------
SEND: <message xmlns="jabber:client">
  <gcm xmlns="google:mobile:data">{"to":"cdcdcdcdcxxxxxxx",
                             "time_to_live":"600",
                                "dry_run":true,
                             "notification":{
                                 "title": "Portugal vs. Denmark",
                                 "text": "5 to 1"}
                          }</gcm>
</message

Socket            : 0x00000E54
Index             : 5
Type              : TCP
Local Address     : 192.168.1.2
Local Port        : 60376
Remote Address    : 74.125.68.188
Remote Port       : 5236
Send Calls        : 6
Receive Calls     : 13
Sent              : 1,155
Received          : 630
Closed            : Yes
i HAVE CHANGED FIREWALL RULES


getting error:
SERVER IS CLOSING xmppClient_OnClose

any ideas how to solve.
This post was edited 7 times, last on 2015-06-28, 14:19 by Alex.
Avatar
Alex #4
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you id is empty. Generate a unique id on your messages.

See also here for some XMPP example logs and more documentation:
http://www.grokkingandroid.com/xmpp-server-google-cloud-me…

The documentation at Google is not very complete :(

Alex
Avatar
atulloona #5
Member since Jun 2015 · 6 posts
Group memberships: Members
Show profile · Link to this post
hey Alex,

I got the error,basically i was sending message on this event xmppClient_OnLogin, send message should be after login and bind events in my case.

Thanks for support.

Regards
Atul
This post was edited 3 times, last on 2015-06-29, 13:04 by atulloona.
Avatar
Alex #6
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
yes, try to wait for the OnBind event and set your message there.
You can also set AutoRoster and AutoPresence to false, those are not needed for GCM.

I just tried your code and it works fine for me.

Alex
Avatar
Alex #7
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you can use this class to build teh Gcm Xml element:

  1. using Matrix.Xml;
  2.  
  3. namespace Matrix.Xmpp.Google
  4. {
  5.     public class Gcm : XmppXElement
  6.     {
  7.         public Gcm() : base("google:mobile:data", "gcm")
  8.         {
  9.         }
  10.     }
  11. }

This code will be in the next MatriX release.
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