I have downloaded and setup the Android gcm-client and gcm-demo-server (http server) from http://code.google.com/p/gcm/ . I have managed to receive downstream messages in my Android gcm-client app. I have done numerous tests with the following characteristics:
The server used either a browser API key or a server API key.
The data connection was either 3G or WiFi
The sent message included/didn't include additional data.
The sent message had/didn't have a collapse key.
The sent message had delayWhileIdle set to false.
The sent message had timeToLive set to 0 or 5 minutes.
The server was located in two different locations within Europe.
The Android app run in two devices located in different places within Europe.
In all cases the app receives the sent messages after 25-30 sec from the moment they were sent. However, I have tested other Android applications that use GCM downstream messages and in most cases the messages arrive almost instantly (<5sec).
Is there something I can change in the client or server in order to have the messages received in the app sooner?
I also tried to use the gcm XMPP server (Java application using Smack) given in http://developer.android.com/google/gcm/ccs.html but I didn't manage to sent any messages. The response I receive from GCM Cloud Connection Server (CCS) says "Project XXXXXXXXXX not whitelisted". The most possible reason is that my registration for CCM has not been approved yet as described in Google CCS (GCM) - project not whitelisted . As I have read in various websites, the approval usually takes more than 2-3 months, so I will most possibly not be able to test the XMPP server soon.
Is it possible that you can only receive nearly instant messages by using an XMPP server? Does anybody have any experience of the delays encountered using an XMPP server?
Thanks in advance
I think that the problem is in the android gcm-client demo that are retaining the message, not in the gcm-server.
In GcmIntentService.java file of gcm-client demo, it can be seen that the function protected void onHandleIntent(Intent intent) have the following code:
[...]
// If it's a regular GCM message, do some work.
} else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
// This loop represents the service doing some work.
for (int i = 0; i < 5; i++) {
Log.i(TAG, "Working... " + (i + 1)
+ "/5 # " + SystemClock.elapsedRealtime());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
}
[...]
This code sleeps android application 5 seconds every iteration (total 25 seconds) before deliver a notification message. You can delete this code due to is an example and you can insert into else if statement some work before show notification.
I have implemented a xmpp server and I receive the notification in <5 seconds, without this working code, of course.
Hope this help and sorry for my bad English.
Related
I have enable stream management in both side client or server. I have two users A and B. Both users are online.Then user A suddenly lose his connection. but A user still appear online on user B and as well as on server. During that time user B sending message on user A. Those message are not lost but when user A is appear online again it will receive those message after 2-3 minute.and i will get message stanza on Offline storage and delivery receipt i will got on SM storage.This issue same occur on one to one chat and mucLight. have i need to customized any mongooseIM modules. Please guide me why users received delay message when their are lost his connection. is it possible to changed SM storage to offline storage(MAM). here's link for same issue i have found same issue on this link (https://www.ejabberd.im/faq/tcp) but have not lost my messages but just received it delay.
I am use smack-4.2 lib on my Android app.and following code used to enabled stream management in XMPPTCPConnection.
static{
XMPPTCPConnection.setUseStreamManagementDefault(true);
XMPPTCPConnection.setUseStreamManagementResumptionDefault(true);
}
Here's my ejabbered.cfg file for mod_stream_management module
{mod_stream_management, [
% default 100
% size of a buffer of unacked messages
% {buffer_max, 100}
% default 1 - server sends the ack request after each stanza
% {ack_freq, 1}
% default: 600 seconds
% {resume_timeout, 600}
]},
I have also enable following module on my config file
%% Only archives for c2c messages, good performance.
{mod_mam_odbc_user, [pm]},
{mod_mam_cache_user, [pm]},
% {mod_mam_mnesia_dirty_prefs, [pm]},
% {mod_mam_odbc_arch, [pm, no_writer]},
{mod_mam_odbc_async_pool_writer, [pm]},
{mod_mam, []}
I found little solution here smack connect to xmpp server with previous stream id but its not work on mongooseIM-2.0 server.
Thank you in advanced.
I'm assuming below that user A, when they reconnect, is not using Stream Resumption (as defined by XEP-0198: Stream Management) and merely starting a new session.
This means that on the server side there's still a dangling process waiting for Stream Resumption to happen. When user A is already reconnected to the server, the dangling process times out (which takes resume_timeout seconds) and sends the messages it had stored for delivery in the outgoing message buffer.
If you don't like this behaviour, you can do one of these:
a) (not advised) disable Stream Management and send a Message Archive Management query (that is use mod_mam) to have the most up to date conversation state each time you establish a new connection to the server
b) leave Stream Management enabled, but use Stream Resumption if only possible; that is, you always try to resume the previous session, unless you don't have the previous session ID or the server rejects the resumption request; ideally you would also use Message Archive Management
c) use Delayed Delivery aka mod_offline, but risk that in some rare cases, if you use multiple devices, the messages might be sent to a wrong device; for example, if you have a phone and a laptop, it might happen that your messages will reach the laptop, but never reach the phone
Did you try using mod_ping and configure on ejabbered.cfg file.
{mod_ping, [{send_pings, true}]},
fore more details please follow this link mod_ping
Hi I am trying to implement a chat service using gcm. I follow the below link this
I am able to register the device but not getting the message to the device, i got an output like this from the php side
{"multicast_id":4761920147140850331,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1396947152466532%978fee92f9fd7ecd"}]
i tried to send the message using http://gcm-alert.appspot.com/
getting a response success but not showing on the device.
I am using browser api key
the output shows the message is sent successfully, there is something wrong on application level, its hard to tell without any details, but make sure you are connected to internet and make sure that messages are not getting blocked by your firewall, it happened to me when I was testing my app on our corporate network
The output said that message send perfectly,
So question is that how to analyze problem,
Please switch on data network mode (Data plan), switch off Wi-Fi connection,
Then send to try again,
now question is that you can not check that cause app is work in local web service,
so, In GCMBaseIntentService class method name is onMessagem please print log on messages receive like this,
protected void onMessage(Context ctx, Intent intent) {
String message = intent.getStringExtra("message");
Log.d("Message=",
}
Please check this all in mobile, and mobile are connected to system, and you can check all log, so, you can analyze clearly where is the problem.
The message shows whtever you did on the server side is absolutely correct. Check your client side code. The manifest permissions should be accurate to receive messages from GCM
I have an .Net windows service that sends GCM push notifications via https://android.googleapis.com/gcm/send.
The service periodically sends batches of approximately 10,000 messages at a rate of 10 / second. With each batch, 5 - 10 of the messages will cause a "502 Bad Gateway" response. The messages that generate the 502 always go through with a second try.
Is this normal? Could I be sending too many messages too quickly?
According to the GCM guide, all 5xx error codes should be treated as temporary errors, and requests that get these errors should be retried :
5xx Errors in the 500-599 range (such as 500 or 503) indicate that there was an internal error in the GCM server while trying to process the request, or that the server is temporarily unavailable (for example, because of timeouts). Sender must retry later, honoring any Retry-After header included in the response. Application servers must implement exponential back-off.
I don't think 10 messages a second is too quick. As long as your code handles this error and retries, I don't think there should be any problem.
I try to implement an application with Google Cloud Messaging from http://developer.android.com/guide/google/gcm/gs.html
Sender sender = new Sender(myApiKey);
Message message = new Message.Builder()
.collapseKey("1")
.timeToLive(3)
.delayWhileIdle(true)
.addData("message", "message is created at builder")
.build();
Result result = sender.send(message, reGid, 5);
System.out.println("result of message is "+result);
and consequently i get a message id and can see from console; but i want to show message at my device with a toast.
GCMIntentService.java:
#Override
protected void onMessage(Context arg0, Intent arg1) {
Log.i(TAG, "new message= ");
Toast.makeText(this, arg1.getStringExtra("message"), Toast.LENGTH_SHORT)
.show();
}
from GCM Advanced Topics:
When a 3rd-party server posts a message to GCM and receives a message ID back, it does not mean that the message was already delivered to the device. Rather, it means that it was accepted for delivery. What happens to the message after it is accepted depends on many factors.
In the best-case scenario, if the device is connected to GCM, the screen is on, and there are no throttling restrictions (see Throttling), the message will be delivered right away.
I can't understand what means "the device is connected to GCM".
How can device connect the GCM, connecting the internet and running the application from device isn't enough?
Connecting to GCM depends on a few things.
The device has registered to receive messages - GCMRegistrar.register
The device has a connection that allows the message to be delivered
The device meets certain requirements for installed software that allows the delivery of messages - namely the Google API's - Minimum SDK 2.2
UPDATE:
When you send the message you receive a status response which if everything is ok will mean a message id. The device that sent the message will not receive the message unless the message was sent to that device (using the devices registered GCM id). The devices registration id is return following the call from the device to register.
Please note that with GCM there is no guarantee that the message will be delivered. It is normally very reliable but should not be used if delivery is critical.
Yes onMessage() is the entry point for a new message being received by the device.
You should follow this link to get answers of your all questions :
http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
you just need to implement client and server. I have implemented on my own PC and got running code. I have already tested on PC to Mobile also.
Source Code is available. you just need to download and follow some easy steps.
I bet you will get your code running within 30 min.
Happy to Help !!
i'm using aSmack in my Android app to receive messages from my Desktop-Jabber-client. This works fine and even if my android phone is offline (after the connection was closed properly) it will receive the offline messages after the next login.
But when i enter the airplane-mode on the phone or shutdown the phone so that the connection is abruptly closed (without calling disconnect() on the Connection-object) the phone stays "online" in the contact-list of my Desktop-Jabber-client for a while and i can send messages to it. However these messages never arrive. Even though the phone logs in to the server again. These messages are lost.
Does anyone know how to fix this issue? Losing messages in a chat is not an option. :)
EDIT: Added Test-Code
BroadcastReceiver: http://pastebin.com/cFLzGXgy
Service: http://pastebin.com/wLpQCQfT
The first one is a BroadcastReceiver starting the service (second URL) each time the phone is connected to a network.
PS: This is only a test-code! You must change the server/username/password if you want to use/test it.
You can try to send delivered message from client b to client A when the message arrival. The problem is if the client A is offline (no connection break) the delivered confirm don't send until the user receives the message and the client B can't re-send the message.
you can try to send acknowledgement of receiving the message using Smackx Message Events
this will assure the message is delivered else you take corrective action.
this problem occurs when your connection broke.
You need "Stream Management" XEP-198 enabled connections to achieve this messages. refer to this blog : http://op-co.de/blog/posts/XEP-0198/ Basically it allows for stanza acknowledgement and stream resumption, which is exactly what you want to do in case.so you should wait till smack will 4.1 release.