4

Basically, I have a server and mobile application. Mobile application subscribes on events from server. Server than, after some time publishes events to all subscribers (yup, good old publish/subscribe).

The thing is that the server uses HTTP to send notifications. So I need within my application something like HTTP server for handling those requests asynchronously (i.e. without any special initial request).

Is there any facility available? I am thinking about creating a Socket and Listen to it, but here the problem arises of conversion of HTTP from Socket data. I've already read some questions around StackOverflow, but none of them points the same problem directly. Or did I miss something? Anyway, the help is very welcome and appreciated.

Community
  • 1
  • 1
87element
  • 1,909
  • 3
  • 19
  • 29

5 Answers5

3

C2D is good... but it's still in beta phase and you have to accept the Google ToS. I'd implement it by my self using something like MQTT... it's pretty easy to implement, fast and you control the data: http://tokudu.com/2010/how-to-implement-push-notifications-for-android/

Cristian
  • 198,401
  • 62
  • 356
  • 264
  • C2D is not the solution, want to avoid the registration, and I cannot, actually, change the server etc. Will check MQTT, thanks for pointing out. – 87element Mar 16 '11 at 17:59
2

You should look into Cloud2Device Messaging. I believe that's how GTalk works.

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
0

Try this answer about push notifications via the Android Cloud to Device Messaging Framework.

I don't think you will be able to receive HTTP requests, or even that your phone would have a stable IP address.

Community
  • 1
  • 1
Matthew
  • 44,826
  • 10
  • 98
  • 87
0

There's two options for handling connections in the background...

AsyncTask and Service.

A service works like receiving a text message (no constant polling needed), whereas the AsyncTask would constantly be polling.

I think using a Service is the best way to go, as long as you are not concerned with performance. I think there may be a few second delay on when the user receives the notifications through a service.

An AsyncTask is definately more battery hungry, but will probably perform in a more timely and reliable manner.

Matt
  • 5,461
  • 7
  • 36
  • 43
0

You can use PUSH notifications or start a run a JETTY server on your android.

I have an application working quite the same way, running a JETTY server on android.

Panthro
  • 3,247
  • 2
  • 32
  • 37