Can we suspend the activity till we get a response from server?

5 replies [Last post]
ramz
Joined: 05/11/2010
User offline. Last seen 12 weeks 2 days ago.

Hi,

Can we suspend the activity till we get a response from server?

I have posted data to the php server through HTTPClient. The php server searches the database for the response. But if there is no response in the database, a person from the server side need to reply to it, like a chat. My requirement is to wait for reply and to get the reply from the server with no triggering from the user side.

I have a php page that selects new entries from the database. Now I need to call this file from the activity. Please help me in implementing this...

Robert Green
Robert Green's picture
Joined: 02/18/2009
User offline. Last seen 16 hours 56 min ago.
You'll want to start a thread

You'll want to start a thread to retrieve the data and have it call back to your activity or to a handler of some type so that the UI can respond when data is available.

ramz
Joined: 05/11/2010
User offline. Last seen 12 weeks 2 days ago.
Thanks for the reply. I

Thanks for the reply.

I started a new thread, call the data to the activity and was successful in it. A user at the server side sends reply to the message, there may be delay for response. I want to get that reply message into my application when the user provides one. The application is miniature form of a chat system, When the client side user sends a message, a user at the server side sees it and replies to it. There will be no event from the client side.

I want to periodically check the server for reply from the application. Please suggest me how to do it?

Should I implement it from the server side itself?

Robert Green
Robert Green's picture
Joined: 02/18/2009
User offline. Last seen 16 hours 56 min ago.
Ah ha. Now I understand -

Ah ha. Now I understand - you're wondering how to deal with 2-way events in a request-response model. There are several approaches you can take:

1) Keepalive connection where the server responds when appropriate and the client just stays connected, listening
2) Polling - the client requests an update every n seconds

I believe the most common way to do real-time systems using HTTP these days is option #1, but this is not my area of expertise so you may want to look into it more.

ramz
Joined: 05/11/2010
User offline. Last seen 12 weeks 2 days ago.
Can u please suggest me some stuffs to refer to....

Hi,

Thanks for the reply.

I couldn't find any hint searching google. Can u please suggest me some stuffs to refer to....

thanks in advance.

Robert Green
Robert Green's picture
Joined: 02/18/2009
User offline. Last seen 16 hours 56 min ago.
Search for "http persistent

Search for "http persistent connections" and start reading through everything. I don't personally know how to do it - I just know that it's probably what you want.