Hello Kostya,

I've tried what you said but my problem remains. I'm fact the problem
only occurs when the device goes in sleep mode. If I let it connected
to my PC (the screen never goes totally black), every thing is working
fine. I've got a wakeLock in my application:

final PowerManager pm = (PowerManager)
getSystemService(Context.POWER_SERVICE);
m_partialWakeLock = pm.newWakeLock((PowerManager.PARTIAL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP), APPLICATION_NAME);

I've implemented something that connect to my server each 3min when in
sleep mode. It's not using the connection which is supposed to be
alive because I can't send data on it. The server is as is and I can't
change anything on it. This mechanism works, I manage to successfully
connect to my server. But still after 5min my opened connection
doesn't receive data anymore.

Something in the sleep mode is putting my connection in "hold", I
don't know. I'm not even sure that the connection is closed. It seems
it's just stuck somewhere.

The server is closing correclty any connection since when not in sleep
mode I always detect it. So my first message has wrong information.


Cédric


On 22 sep, 12:26, Kostya Vasilyev <[email protected]> wrote:
>   Like I said before, detecting a broken connection on the receiving end
> is difficult, since TCP/IP does not have keep-alives. That's left up to
> the application protocol.
>
> Perhaps what you could do is have your application periodically send
> small amounts of data, just to make sure the connection is still there.
> Just make sure your server can deal with it - actually read the data
> past the initial HTTP request, if only to drop it on the floor.
>
> -- Kostya
>
> 22.09.2010 13:21, Cydrike пишет:
>
>
>
>
>
> > 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-Masquerle 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 -
>
> --
> 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 -

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

Reply via email to