My clients are Android devices. A client wants to send some info to another client which will first be sent to the app server and then the server will notify a middleware service(some kind of message broker) which will be responsible for sending the target client a push notification(to tell it to poll from the app server).
I want to know:
How will this middleware service identify which client device to notify?
more concretely, How does a push notification server locate which physical device to fire off the notification to?
My requirement is that the client should be able to obtain notifications even while using a VPN or proxy(similar to WhatsApp). Also, if the client is powered off then the middleware queues the messages and delivers them once the client power backs on again.
I have been looking at things like Firebase Cloud Messaging and MQTT brokers and stuff but I want to implement similar things on my own.
I want to implement this in Java.
Your client ( having an unique id and token ) will send the message to another client who also have a unique id and token in the database .. So the,
Server will map the receivers' id to the receivers token and send the notification to the receiver..
The database(backend) will have unique ids (maybe primary keys) against each client and also a unique token (for sending notification) against each client. So , when the sender-client sends the message , the backend script maps the receiver-client's (to whom the sender is sending) id to the receiver clients token. Then send the notification to the particular token.
Related
I am developing an application in android (Twilio Android Client) using Twilio, which consumes the Rest API.
I can successfully send the SMS using the rest API. However, when someone replies to SMS/MMS, the server will get that message because Twilio will hit that URL.
But on the other hand, I don't understand how to update the client device when we receive an SMS/MMS using Twilio.
Is there any way to update or send the message (SMS/MMS) to the client device when a server receives an incoming message(SMS/MMS)?
You can configure a URL for SMS/MMS in your twilio number. Now, when the user replies to this number, this script in this URL will be executed. In this script, write code to forward SMS/MMS to your android device's phone number.
If you want to handle replies solely via your app, (ie, not by conventional SMS and MMS) then store reply SMS and MMS in server. Then write an API in server to get these messages. Now write code in android to periodically query this API and retrieve these messages.
My android app uses GCM to send or receive text messages. At first, when a user install my app, it uses the GCM api to get a GCM_id from Google. After getting this long GCM id, app sends this id to my web server to say that this client is registered with that id.
My question is that about this step. Since firstly app gets the GCM id and sends it to my web server, I think, someone can listen the requests of the app and sends dummy GCM_ids for this client (or any other clients if guess my client id format). How can I secure this step to prevent unwanted interrupts and attacks.
While creating gcm_id, if google would send this id to my server also before sending it to client, it would be a solution to my problem. But google sends it to client only directly.
ps: Using ssl is not a solution I think. Because it can also be opened by programs like fiddler .
I want to implement push notification for Android and IOS, we have our own app for android and ios from that app user can send various request and after request completion user will get notification by using push notification.
So my question is
1. How I can detect the device to which i need to send notification.
2. I am new to GCM so can somebody help me from how to start this.
3. Every where I have found GCM send RegId to server, so whenever request comes every time I need to generate RegId or I need to check whether that user is registered or not if not register it first and then sends notification.
Thank You.
You don't need to regenerate the Registration ID every time.
In simple terms:
Client registers with GCM and client gets a registration ID.
You need to store the registration ID in your server.
Your server will need to send a list of registration ids with message content to GCM. GCM will respond with a list of successful and unsucessful messages to
the server.
The push events that are successful will go to the corresponding device. Note that the push notification will only show if you have
code on the client that receives it in addition you need to have the
app installed.
The client and server code example on the documentation is easy to implement. Have fun :)
I developed a client on android app and a server, but now I discovered the GMC- "Google Cloud Messaging for Android"
Is there any way to connect the GCM to my server, without changing everything?
The client send data to the server with socket, and what I need is that the server will send the data to the GCM, and the GCM will send the data to all the clients.
I don't need the clients to send data to the GCM, all what I need is :
client -(socket)--> server ---> GCM ---> clients
Someone have any idea how to do that?
Thanks in advance!
You can send GCM messages from your Java Server. The simplest way is to use the server library supplied by Google (gcm-server.jar).
The code for sending a message is as simple as :
Sender sender = new Sender(apiKey);
Message message = new Message.Builder()
.delayWhileIdle(true)
.addData("key1", "value1")
.addData("key2", "value2")
.build();
Result result = sender.send(message, registrationId, numOfRetries);
In addition, you'd have to check the result, to see if your message was accepted or rejected by GCM server.
This example shows how to send a message to a single device. There's a similar way to send the same message to multiple devices.
Finally, you'll have to implement some web service that accepts a registration ID from your app, and saves it in your DB.
Currenlty I am trying to develop a simple chat application for Android. I want to create something that works like WhatsApp. Because it should be realtime, I think C2DM is the best way to send a notification when a user sends a message to another user.
Because I have read that C2DM is build for noticiations only, and not for messages I have to find a way to deliver those messages to that other contact.
Now, I have a application server, that can send C2DM notifications. But what's the best and the most energy saving way to send and receive the 'textmessages'?
I have read about polling, but it's not that energy saving I think. I have read something about 'XMPP', but how can I combine that with C2DM?
User A sends message to User B, that is, it sends a message to your application server.
You app server receives a message from A to B. It sends a C2DM notification to B telling that there is new data.
User B receives the C2DM notification of new data, connects to your app server and retrieves the message from User A.
This mechanism only pushes data, there is no polling.