For a blocking stream, -1 is closed. The issue with SSL sockets in HTTP code failing in some way or other comes up on this list every once in a while.
Think I remember a suggestion to disable SSL session cacheing (negotiated SSL sessions are cached and reused, if the code sees the same pair of endpoints). Try searching the group's archives, see if you can come up with something useful. It's also not clear to me if your code actually uses HTTP - in that case, using Apache HTTP classes doesn't make sense to me. There are SSL sockets in javax.net.ssl that don't assume HTTP. -- Kostya 2011/6/12 Indicator Veritatis <[email protected]> > I think you may be jumping the gun by assuming that read() returning > -1 means the stream is invalid: what it REALLY means is only that the > end of the stream has been reached, there are no more bytes to read: > it does not explain WHY there are no more to read. How can you exclude > the possibility that no bytes are yet available but the stream is > valid? Are you catching any exception that might be thrown by > getInputStream()? > > On Jun 10, 6:52 am, Lorie Pisicchio <[email protected]> wrote: > > Hello, > > I am developping an application that is connecting to a distant server > via > > SSL. > > I have a watchdog monitoring network connection. > > When the phone looses the network connection while my application is > > running, I close the current socket and start a periodic task to try to > > reconnect. > > Problem starts when network is back : my application creates a brand new > SSL > > Socket, and start reading in it (socket.getInputStream().read()). Here, > the > > read action returns immediatly with result -1 (which I interpret as > socket > > input stream being not valid). > > The periodic task runs infinitly, create a new SSL Socket, start reading > in > > it, and immediatly get -1 result... > > > > The code for creating the socket : > > SSLSocketFactory socketFactory; > > socketFactory = SSLSocketFactory.getSocketFactory(); > > > > > socketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); > > Socket socket; > > try { > > socket = socketFactory.createSocket(); > > HttpParams params = new BasicHttpParams(); > > socket = socketFactory.connectSocket(socket, > > remoteIp.getHostName(), remotePort, null, 0, params); > > } catch (Exception e) { > > Log.e(TAG, "Unable to create socket", e); > > } > > > > For information, if I connect to the server using standard connection (I > > mean, not SSL), everything is OK. > > Do you think it can be a bug in > org.apache.http.conn.ssl.SSLSocketFactory? > > > > Any help would be appreciated! > > Best Regards, > > Lorie. > > -- > 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 > -- 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

