1

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?

1
  • how do you send the second data ? Commented Oct 20, 2010 at 6:15

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
.. 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 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.
0

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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.