87element
87element

Reputation: 1939

Is it possible to receive Http requests asynchronously on Android?

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.

Upvotes: 4

Views: 3614

Answers (5)

Panthro
Panthro

Reputation: 3590

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.

Upvotes: 0

Cristian
Cristian

Reputation: 200140

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/

Upvotes: 3

Matt
Matt

Reputation: 5511

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.

Upvotes: 0

Matthew
Matthew

Reputation: 44919

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.

Upvotes: 0

Robby Pond
Robby Pond

Reputation: 73494

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

Upvotes: 2

Related Questions