views:

56

answers:

3

My android app sends data to a servlet every 10 seconds. the servlet receives the very first request and responds back. but the servlet doesn't receive the second set of data that the client sends after the next 10 seconds. could some one please tel me how do i go about doing this. is it something related to session?

A: 

your servlet is probably finishing execution after it sent the first response.

dvhh
+3  A: 

Http is not a persistent connection protocol. You should consider issuing one http request for each set of data you need to send.

If a persistent connection is mandatory (but I don't really see what would force you to do that), you have to work with the TCP protocol... and you won't be able to use a servlet on the server-side but a specific application listening to a specific TCP port.

Kevin Gaudin
not the whole story, the connection is maintained as long as the servlet is running and the client dosen't consider the server is timing out. the server can send data if its output is unbuffered or flushed properly.
dvhh
@Kevin... if that is the case. could you please tell me how can I maintain a session for a specific android device on the server. the server needs to know to whom it is responding to...this is a simple navigation system...so gotta keep track of the user@dvhh.. how can we make the client consider about the server timing out...do you have any idea...thanks
raqz
@raqz you have to send some user id data with each http request. @raqzz anyway, with http, once the request is sent, the client cannot send any data again to the server in the same http connection. You only can wait for data from the server until the server closes the connection.
Kevin Gaudin
@Kevin..thank you kevin
raqz
A: 

This sounds very much like as if you're reusing an existing URLConnection instead of creating a new one for each request and that you're suppressing the exceptions by empty catch blocks and/or ignoring the stderr.

For each independent request, you have to create a new URLConnection.

URL url = new URL("http://example.com");

// First request.
URLConnection connection1 = url.openConnection();
// Process it...

// Second request.
URLConnection connection2 = url.openConnection();
// Process it...

// Etc...

The session management only comes into picture when the servlet is storing something in the HttpSession which you would like to re-access in the subsequent requests. This doesn't seem to be the case here.

BalusC
well...in the next set of task i will have to implement the session management functionality...so i wil be requiring it..thanks BalusC
raqz