I'm developing a queue of messages for a messenger app.
On Android if the connection is lost, messages is save on the queue and as soon as the 3G or wifi is back the messages go out of the queue. This is possible thanks I'm listening a broadcast receiver which alert me when the connection is back.
Is there anything similar on iOS?
Any workaround on iOS to achieve this behaviour?
You determine the restoration of an internet connection via the Reachability class. You can attempt resending once Reachability tells you that you have an Internet connection again.
Related
I have a service that runs every min to check if the global XMPPConnection object is connected and authenticated. What I found is that after an hour or so of idle mode, the connection object shows it is connected and authenticated but it does not receive any messages.
The connection seems to be broken without the Connection object knowing about it. Please let me know what I could implement to check if the XMPPConnection object is truly connected and can receive messages even after a long while of inactivity.
Appreciate your help.
hi If you are using openfire then go to Server settings then Client connection and change settings to Do not disconnect clients that are idle.
This help you to user available all times.
Second solution for your problem if you are not using any service for making user online. Then do that thing.
Here i made example of one to one chat and it available on github.
thanks hope this help you.
Depends on your XMPP server implementation, you can simply send message to yourself and check if you receive it.
Another way would be to perform XMPP service discovery, fetch your roster list etc. in short - do something that requires client-server communication.
I and working on a Chat Application using SMACK 4.1.7.
I receive connectionClosedOnError when Wifi is changed from A to B and I get Network Change Event through broadcast receiver.
I need to figure out how to handle this to keep connection active with server.
You should try using the smack ReconnectionManager for handling automatic reconnect after the network switches.
http://download.igniterealtime.org/smack/docs/4.1.7/javadoc/
Smack's ReconnectionManager takes care of handling the reconnect anytime your connection is dropped unexpectedly.
You might also want to check this post
https://ramzandroidarchive.wordpress.com/2016/03/14/handling-connection-break-issue-in-smack-4-1/
It gives a good explanation on how to maintain a persistent connection.
I'm working for an App Android and I need my phone was always connected to my server MQTT...
But my phone can lost his connection(Tel :[FIN;ACK]; Serv:[FIN;ACK];Tel:[ACK]); after that, when he send a [SYN] message for connect it to the server MQTT, the serveur send an [RST,ACK]... And this while the service of my app is in activity.
In my case , i MUST to re-launch my server if i want my phone can be reconnect, but, i can't reboot my server (multi-phone possible, and i need real-time performence).
There is there a possibility to connect my phone without reboot my server?
Thank's for time.
Best regard
Guillaume
I think your problem is similar to the one I had. The connection was half closed. See http://www.codeproject.com/Articles/37490/Detection-of-Half-Open-Dropped-TCP-IP-Socket-Conne for details.
The way I solved this was to i) add keep alive msgs, every 5 secs. from the phone to the server and ii) have the server close the connection if there was no incomming data for 15sec. See http://www.forward.com.au/pfod/CheapWifiShield/index.html and www.pfod.com.au
MQTT includes keepAlives (PING request msgs) so you only need to modify your client to specify a short keepAlive interval
see http://www.hivemq.com/blog/mqtt-essentials-part-10-alive-client-take-over
to have the MQTT server to more quickly close the connection once it stops getting your data or keepAlive msgs.
Although the above link states
"The broker will close the previous connection to the same client (determined by the same client identifier) and establishes the connection with the newly connected client. This behavior makes sure that half-open connection won’t stand in the way of a new connection establishment of the same client."
So you should not be having this problem at all !!!
I am creating a chat app using smack using openfire sever by XMPP protocol. I can chat with other user and working well. I created connection in Service class. So i am able to get notification message when i am not in my application but i get my service is restarting again and again when network problem, network change, network slow etc. So my connection is lost. and user is not always able to chat.
So i solved connection problem. like as
if( service is not runing)
start my service
else
if(connection is NULL or not Connected)
reconnection . so my connection is created
My service class:-
if(connection is NULL or not connected)
reconnect. so my connection is created
else
not connected.
But now if my service is runing and connection is lost. and i open my application , a new connection is created. This connection is created by application not services. So now when i am not in my app , i did not get any notification for incoming message because incoming message was coming by service connection.
Now i have involved. please expert help me. How can i solve?
Is there way for push notification in openfire?
You could try binding to your service;
Create a method in your service called connect()
When the application is started instead of creating a connection object in activity class, bind to the service, call myServcie.connect();
This way the connection is still owned by the service,
Other way to communicate with the service is via intents.... send an intent to the service when activity is created and have the BroadcastReceiver in the Service call connect();
One thing to watch out for is continuously reconnecting in a mobile environment is not recommended.... battery life being what it is. You can check to see if the application package is the one that is showing and then reconnect if it is etc.
James
Iam connection to services trougth my app, I woul like to check if the connections gets broken, alert a message than.
Or is this taken carre of in android?
If not, How should I take care of it? is there a timer?
If you are connecting to built-in services of Android, for example Connection with GPRS, WIFI or MOBILE 3G connection, then you can register a Broadcast Receiver that will tell the user when the connection is lost.
But if you are connecting to your custom-made services, for example ABC Application, then you would have to make your own service, that will periodically (example every 15mins) will check the connectivity with ABC Application. Hope this helps.