New information: It seems that I don't receive Connection Reset by Peer errors because Android has "dropped" the connection.
My exact test case is the following: - I start my application which creates the request with the previous posted code - the app reads the request response waiting for the server - I put the device in sleep mode by pressing the power button - I wait 5 minutes (nothing special happens in logs apart from garbage collector actions) - I wake up the mobile and force the server to send me something - Nothing arrives on the mobile anymore, the connection is stucked on the read No error can be seen in logcat, no exception is raised. It seems that Android has just stop using my connection. Is there some kind of mechanism that kill idle connections while in sleep mode ? Cédric On 6 sep, 14:57, Cydrike <[email protected]> wrote: > Cloud 2 Device Messaging seems to be very interesting but I can't use > it for many reasons. > > I've explicitly tested returned value of Read() method to detect -1. > But it doesn't change anything. > My application has been developed for Windows Mobile 6.5 too. Windows > Mobile always detect the Connection Reset by Peer exception. Test > protocol is exactly the same as the one used for Android. > How could this difference be explained ? > > Here's the code I use to create my request with Android: > > HttpURLConnection connection = (HttpURLConnection) new > URL(request).openConnection(); > connection.setDefaultUseCaches(false); > connection.setUseCaches(false); > connection.setDoInput(true); > connection.setInstanceFollowRedirects(true); > connection.setConnectTimeout(CONNECT_TIMEOUT); > connection.setRequestMethod("GET"); > > Cédric > > On 6 sep, 11:20, Kostya Vasilyev <[email protected]> wrote: > > > > > The server doing a graceful close can be detected on the client: > > read() will return -1. > > > A lost connection (not gracefully closed) generally can't be detected on > > the client. TCP/IP does not transmit data unless your application does, > > so a lost connection looks the same as a connection that simply doesn't > > have any data to receive. > > > There is a TCP/IP option to do keepalives at the protocol level, > > SO_KEEPALIVE, but I wouldn't count on it working reliably all the way > > from the phone to the server. > > > I recommend you look at Google C2DM (Cloud 2 Device Messaging). > > > -- Kostya > > > 06.09.2010 11:37, Cydrike пишет: > > > > Hi everyone, > > > > I'm facing an annoying problem here. > > > My application is connected to a server that sends some data from time > > > to time. It's some kind of eventing server. In order to receive data, > > > I'm connecting to the server with an HttpURLConnection, retrieve the > > > response InputStream and loop on it with the read method. The > > > connection is always open. > > > > The distant server is cutting the connection every 5 minutes (for test > > > purpose). When connection is closed, my application has to reconnect > > > again. We detect a Connection Reset by Peer exception when the server > > > closes the connection. The problem is that most of the time, I never > > > receive the Connection Reset by Peer exception. So my application > > > can't know that is has to reconnect and it's stucked on the read > > > instruction. > > > > The InputStream.Read() method shouldn't always raise an exception if > > > the connection is closed? > > > What can I do to always detect Connection Reset by Peer exception? > > > > Thanks for any help, > > > > Android 2.1 > > > HTC Desire > > > > Cédric > > > -- > > Kostya Vasilyev -- WiFi Manager + pretty widget > > --http://kmansoft.wordpress.com-Masquer le texte des messages précédents - > > > - Afficher le texte des messages précédents -- Masquer le texte des > > messages précédents - > > - Afficher le texte des messages précédents - -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

