Gaurav Radadiya
Gaurav Radadiya

Reputation: 231

How can I connect FCM server using any reliable XMPP library in C#?

Can anybody help me in connecting FCM (Firebase Cloud Messaging) server using XMPP library using C#?

I want to send Push notification using XMPP.

I am trying to connect it using Sharp.Xmpp as below,

public class XmppConnector
    {
        public XmppConnector()
        {
            string hostname = "fcm-xmpp.googleapis.com";
            string username = "[email protected]";
            string password = "example";

            using (XmppClient client = new XmppClient(hostname, username, password))
            {
                try
                {
                    // Setup any event handlers before connecting.
                    client.Message += OnNewMessage;
                    // Connect and authenticate with the server.
                    client.Connect();
                }
                catch (Exception e)
                {
                    throw e;
                }

            }
        }

        /// <summary>
        /// Invoked whenever a new chat-message has been received.
        /// </summary>
        private void OnNewMessage(object sender, Sharp.Xmpp.Im.MessageEventArgs e)
        {
            Console.WriteLine("Message from <" + e.Jid + ">: " + e.Message.Body);

            //throw new NotImplementedException();
        }
    }

But it does not work, I even tried with another port (5235 and 5236). If you have any examples, do share.

Thanks in advance.

Upvotes: 2

Views: 1631

Answers (2)

Hasiya
Hasiya

Reputation: 1458

I did it using Jabber-net library, which you can download from, here, it includes library and some examples to understand about how to connect to fcm,also it can download through the nuget package manager package name is jabber-net select the latest version. check here for configured sample.

Upvotes: 0

toledomatias
toledomatias

Reputation: 11

I'm using https://github.com/ForNeVeR/Jabber-Net

myJabberClient = new JabberClient();
myJabberClient.User = Globales.FIRABASE_MESSAGING_USER + "@gcm.googleapis.com";
myJabberClient.Password = Globales.FIREBASE_MESSAGING_KEY;
myJabberClient.Server = Globales.FIRABASE_GCM_XMPP_SERVER;
myJabberClient.Resource = "MyTestClient";
myJabberClient.Port = 5235;
myJabberClient.AutoReconnect = 1;
myJabberClient.AutoPresence = false;
myJabberClient.AutoRoster = false;
myJabberClient.KeepAlive = 10;
myJabberClient.PlaintextAuth = true;
myJabberClient.AutoLogin = true;
myJabberClient.AutoStartTLS = false;
myJabberClient.SSL = true;

myJabberClient.OnMessage += async (s, msg) => {
   // Do stuff here
}

myJabberClient.Connect();

I do push notifications with HTTP API. I'm only having problem sending ACK message of upstream received messages to CCS Server, because the ":" character in some registrarion ids

Upvotes: 0

Related Questions