'Push' applications

SteveBee

Member
Licensed User
Longtime User
I'm working on an app that reads changing job data from a web service.
This should be up-to-date, within a few seconds to a minute of any change occurring.

Normally I might go straight for regular polling at the client, but...

1. There may be many clients connected to the server - add them together and there is a fair load (on the server), even if only checking to see if the data has changed.
2. In addition, I read that polling is frowned upon for battery devices, because of the load on the battery (?)

Ok, so a 'push' application will help here, I read; the HTTP connection is kept alive, and the server signals the *client* when new data needs to be sent.

Can we do this in B4a? If so, how?
In particular how is the HTTP connection managed?

Anyone have any experiences?
TIA
Steve
 

dealsmonkey

Active Member
Licensed User
Longtime User
Hi Steve, a few people, myself included are waiting on this ! I have had a look at some thrid party SDK's but my java is rubbish !!

Neil
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
I bet this request will be posted more and more, polling is "expensive" and not realtime.

See this post: http://www.b4x.com/forum/basic4android-updates-questions/9690-xtify-com-b4a.html

It is a great SDK but not many have Java skills at this forum, that is the reason they use B4A.

Would be great if we would have a bunch of library developers that we can support with donations or whatever.

I would be fine to sponsor some libraries. Would be nice if Erel would help to get this running too.

B4A is great but there is still a lot for work to do and people create libraries that are not always needed. On demand would be so much better to bring everything to a more professional level library wise.

BTW, B4A is very professional but i'm talking about the Eco system around it.

Cheers.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I actually checked xtify.com today. I wasn't able to find how does their push model work. Are you sure that no polling is done?

All I found is this:
How does Xtify work?

The Xtify platform includes two basic elements – a web console / service that executes campaign rules and, programming code (SDK) that integrates into a smartphone application to deliver messages to the device and to derive the user’s location.
Which doesn't tell anything.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Erel,

Everything on the site says push, push push. I have tested their service before and i think it uses a persistent connection to push information to clients.

It will be hard to check if they really do push and not pull.

Other services are Beaconpush and Pusher or even Urban Airship but the first two do HTML5 sockets.

I think sockets won't work.

Xtify is my best bet. But if you really want to know I can contact Xtify, i know some people there.

And sure, Google would maybe work but it is very unclear what plans they have right now.

Xtify has a lot of advantages in terms of campaigns, locations etc.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I think that all "push" solutions are actually polled to some extent because devices are TCP/IP clients and servers can't initiate connections to individual clients. Clioents have to initiate connections.

I don't know how Xtify do it but Google C2DM relies on the device inititiating a secure TCP connection to a server and periodically doing a lightweight poll of the server to check that the connection is still alive, and reconnecting if it isn't. When data is available for a device the server sends an indication to the device which broadcasts an intent. A broadcast receiver in the application for which data is available receives the intent, starts a service and retrieves the data over an HTTP connection.
 
Upvote 0

dealsmonkey

Active Member
Licensed User
Longtime User
I have been looking into this more over the past few days and tend to agree with with Agraham has posted.

From what I can gather, the advantage of the C2DM is it offers a single TCP connection for all the apps on the device, rather than each app opening a connection of it's own, therefore saving battery.

I am playing with polling a small response from the server and then changing the server response if data is there, initiating a bigger download.

My main concern is battery life over instant notification for the app I am working on.

Neil
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
the advantage of the C2DM is it offers a single TCP connection for all the apps on the device, rather than each app opening a connection of it's own, therefore saving battery
Corrrect. Also Google has apparently optimised the protocol as much as possible to minimise the number of polls the device makes and the length of time they take - again to save battery use.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
But the problem is C2DM is available only to Android 2.2 and above users. 26% of users are still using 2.1, 1.6 and 1.5.
 
Upvote 0

SteveBee

Member
Licensed User
Longtime User
I am playing with polling a small response from the server and then changing the server response if data is there, initiating a bigger download.

This only deals with half the issue, from my PoV - it still leaves the issue of the SP/query being run on the server in response to the (100s of) clients requesting/polling.

In my understanding (? :) of Push, the connection, initiated of course by the client, is not closed (keepAlive); I guess there might be a primitive Ping simply to test/re-make the connection.

But importantly, it would be SQL triggers (on data change) that would initiate/signal/flag a data re-read required.

Which is all fine & lovely in theory <g>... But how to actually accomplish the connection part?

S.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
I think your assumptions are not completely correct, push is push. Persistent connections is the key issue. The server handles the distribution like websockets.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Stevebee,

Most push technologies are based on things like Comet servers and client side websockets. Even Twitter uses this nowadays. It is very scalable.

I have sent Xtify a message bacause I think they support full push with a server connecting to the client. Their SDK does this.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Agraham,

I think there isn't much polling involved. Push is a real technology and is initiated from the server to the client. The iPhone for example has a persistent connection.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I think there isn't much polling involved.
There isn't a lot of polling, indeed to save battery it should be as little as possible but there must be some by the client to ensure that the connection is available for when the server wants to use it.

Push is a real technology and is initiated from the server to the client.
Yes, but it is over a persistent connection initiated by the client. That's how TCP/IP works. Servers cannot initiate a connection to individual clients, especially those behind a NAT router as they can only see the router.

This paper http://www.dcs.gla.ac.uk/conferences/gi2011/p797-agarwal.pdf describes some approaches to push. It has a description of what they observed of putting a Wireshark monitor on the Google C2DM service.

Google expressly says that the device periodically "pings" the server to check that the connection is present. See YouTube - ‪Google I/O 2010 - Building push applications for Android‬&rlm; push is described at six minutes and thirty seconds, the description of device polling behind it starts at 11 minutes with the ping explained at fourteen minutes.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Agraham,

Just to be clear, i'm not talking about C2DM. I was referring to Xtify and that they support push. Yes, I know a client need to connect first to get a persistent connection.

I was just trying to tell people Xtify can be used (I have no shares or are affiliated with them) because I think it works.

Anyway, would be glad with any push solution even if it does some polling to keep the connection alive.

As said, websockets would be perfect but I guess we cannot connect with native code.

Cheers,
 
Upvote 0

dealsmonkey

Active Member
Licensed User
Longtime User
Agraham,

Just to be clear, i'm not talking about C2DM. I was referring to Xtify and that they support push. Yes, I know a client need to connect first to get a persistent connection.

I was just trying to tell people Xtify can be used (I have no shares or are affiliated with them) because I think it works.

Anyway, would be glad with any push solution even if it does some polling to keep the connection alive.

As said, websockets would be perfect but I guess we cannot connect with native code.

Cheers,

Do you know what the costs are for the paid version ? I see that the free version only allows 300 pushes per client per month
 
Upvote 0

dealsmonkey

Active Member
Licensed User
Longtime User
Hi everyone,

I've been giving this some thought over the past few days and have come up with what I hope is a solution to suit my needs !

I have created a .net asynchronous server that sits on my in house server. On my Android device I open a socket connection to this server and initialize an AsyncStreams in a service module.

The website part of the app then connects to the in house server when a form is filled and the submit button pressed, this in turn tells the in house server to broadcast to the clients the update signal. This signal is handled by the AsyncStreams_NewData

I have yet to scale this, but so far it works well, although I have not tested battery usage (will be doing that tonight)

If any one can offer any improvements or problems to this solution that I have missed, please let me know. I am not ready to post any code yet, so please don't ask, but i will share when I am happy with the results.

Neil


ps. My server is based in the US, I am in the UK and the Android Device is on the three network in the UK. The update is almost instantaneous...
 
Upvote 0
Top