Reputation: 265
I'm developing a Chat App for Android. I have been reading for weeks about XMPP and Google Cloud Messaging (and Firebase Cloud Messaging) and I am still very confused.
Currently, I already setup an XMPP server locally (Ejabberd) and successfully connected my Android App to it using the Smack library.
To my understanding, I need to use GCM or the newer FCM for Push Notifications, so I already created a project in Google Cloud Platform. My Android App can connect to it using the Smack library too (instead of connecting to my XMPP server directly). In my server I have an small Java app that connects to GCM using the Smack library too.
Everything is fine until here. My big confusion is: How can I use my XMPP server with GCM for Push Notifications? Every documentation, examples, guides, tutorials I found for server-side implementations just tell me how to connect to GCM but none tell me how to use my XMPP server in conjunction with GCM. What I'm missing? My Java app just connects to GCM, receive and send messages from and to GCM, but my XMPP server is just sitting there doing nothing. Actually my Android App and server Java App use GCM exclusively, not my XMPP server.
I hope someone can help me to understand this as a whole, I am obviously missing some key elements to achieve this implementation.
Upvotes: 23
Views: 13796
Reputation: 11
Your suggestion is valid for a connection with tcp/ip never drop. which is not the case in Mobile 3G/4G network. So in real 3G/4G network, the mobile client/APP might be in zombie state(disconnected). That is why you need Firebase/FCM to come to play.
Upvotes: 0
Reputation: 3011
I am also building chat application in Android using Smack v.4.1.8 which latest version of Smack, and our server is using ejabberd. I am not use any third party like GCM or Firebase to push downstream message from user to user message. If i am not wrong you going to use GCM or Firebase to push user to user message, if yes just dont do that.
Why? TCP protocol is keep listening a invoke listener which you registered in App when the connecting establish and still connected. Smack has a listener which called "addAsyncStanzaListener()"
addAsyncStanzaListener is used to listen a receive packet in App. They have
public void processPacket(Stanza packet)
You can invoke that, and you will listen the packet over the time.
I do a research about keeping stable connection of Smack. Most of Android Smartphone have each configuration, and restriction. We cannot test all of devices. Here my tips to keep connection stable:
And that's it. Any enquiries, just comment below :)
Best Regard R Aditya Gumay
Upvotes: 1
Reputation: 195
This is a sample java project to showcase the Firebase Cloud Messaging (FCM) XMPP Connection Server. This project is a very simple standalone server that I developed as a base of a larger project. It is an application server that we must implement in our environment. This server sends data to a client app via the FCM CCS Server using the XMPP protocol.
https://github.com/carlosCharz/fcmxmppserver
And also I've created a video in youtube where I explain what it does.
https://www.youtube.com/watch?v=PA91bVq5sHw
Hope you find it useful.
Upvotes: 7
Reputation: 3100
You need to mix both Ejabberd and FCM together, that's how all the big chat apps do it out there. For the very basics, there are 3 components: App Server connected via XMPP to FCM, Ejabberd and your client app.
This is the very basic description of the architecture you should have to achieve what you want.
Upvotes: 19
Reputation: 463
You should set up a Java server which connects to FCM (formerly GCM). Then you can from your device send an upstream message to FCM who then sends that upstream message to your java server and then within that Java server you can handle that upstream message to send a downstream message to the targeted device(s). Then on the device side you can handle those downstream messages being received to give a push notification.
A few useful links:
How to send an upstream message:
https://firebase.google.com/docs/cloud-messaging/upstream#sample-send
How to receive and handle downstream messages:
https://firebase.google.com/docs/cloud-messaging/downstream#sample-receive
How I set up an example Java server:
https://stackoverflow.com/a/38170310/4433653
Upvotes: 5