2013년 5월 8일 수요일

Message pushing on Android without GCM

이전 블로그에서 이전 함 (원본 글 2013/05/08 작성)

[Using MQTT in Android mobile applications]


 - Persistent TCP/IP connection with ping request every 20mins (wake up by AlaramManager)
 - Message lost will be happen during connection closed situation.

 GCM 안 쓰고 하려면 이 방법 밖에 없나.. ?


[How to Implement Push Notifications for Android]

 - Made sample application with same MQTT approach with above

[XMPP messaging pushing related article]


 - 뭐 5분씩 heartbeat을 날려도 배터리 소모에는 별 지장은 없을 거라는 얘기..


 XMPP is a good solution. I have used it for a push enabled, realtime, Android application. XMPP is powerful, highly extensible and easy to integrate and use.
There are loads of free XMPP servers (though out of courtesy you shouldn't abuse them) and there are open source servers you can run on one of your own boxes. OpenFire is an excellent choice.
The library you want isn't Smack as noted above, it's aSmack. But note, this is a build environment - you will have to build the library.
This is a calculation I did on battery life impact of an XMPP solution:
The Android client must maintain a persistent TCP connection by waking up periodically to send a heartbeat to the XMPP server.
This clearly imposes a cost in terms of power usage. An estimate of this cost is provided below:
  • Using a 1400mAh battery (as supplied in the Nexus One and HTC Desire)
  • An idle device, connected to an 3G network, uses approximately 5mA
  • The wake-up, heartbeat, sleep cycle occurs every 5 minutes, takes three seconds to complete and uses 300mA
  • The cost in battery usage per hour is therefore:
    • 36 seconds 300mA = 3mAh sending heartbeat
    • 3600 seconds 5mA = 5mAh at idle
    • 4:95 + 3 = 7:95mAh combined
  • A 1400mAh battery lasts approximately 11.6 days at idle and 7.3 days when  running the application, which represents an approximate 37% reduction in  battery life.
  • However, a reduction in battery life of 37% represents the absolute worst case in practice given that devices are rarely completely idle.
share|improve this answer



 - smack을 사용할 경우 connection을 계속 유지해준다. 내부적으로 heartbeat 관련 사항은 소스를 봐야 할것 같은데.

By default Smack will try to reconnect the connection in case it was abruptly disconnected. Use ConnectionConfiguration#setReconnectionAllowed(boolean) to turn on/off this feature. The reconnection manager will try to immediately reconnect to the server and increase the delay between attempts as successive reconnections keep failing. 
In case you want to force a reconnection while the reconnetion manager is waiting for the next reconnection, you can just use Connection#connect() and a new attempt will be made. If the manual attempt also failed then the reconnection manager will still continue the reconnection job. 


org.jivesoftware.smack
Interface ConnectionListener

All Known Implementing Classes:
AbstractConnectionListenerReconnectionManager

<pre>public interface ConnectionListener</pre>
Interface that allows for implementing classes to listen for connection closing and reconnection events. Listeners are registered with Connection objects.


Author:
Matt Tucker
See Also:
Connection.addConnectionListener(org.jivesoftware.smack.ConnectionListener),Connection.removeConnectionListener(org.jivesoftware.smack.ConnectionListener)

Method Summary
 voidconnectionClosed()
          Notification that the connection was closed normally or that the reconnection process has been aborted.
 voidconnectionClosedOnError(Exception e)
          Notification that the connection was closed due to an exception.
 voidreconnectingIn(int seconds)
          The connection will retry to reconnect in the specified number of seconds.
 voidreconnectionFailed(Exception e)
          An attempt to connect to the server has failed.
 voidreconnectionSuccessful()
          The connection has reconnected successfully to the server.
 


[Android Push Server MQTT]
- 작성자 : 이광운 ultrakain엣gmail.com

scalibility를 고려한 push server 관련 자료.
근데 결론이 뭐지? PT 자료만으로는 모르겠다.
Asynchronous socket I/O를 지원하는 framework에서는 당연히 reactor, proactor를 사용하는 것은 당연할테고..

댓글 없음:

댓글 쓰기