Pergunta

In my Android app when closing the connection(like turning of WiFi) I'm getting an infinite number of this log message [cds] shutdowninput in read which interrupts my app and makes it do tons of unnecessary input checking, I'm using java socket programming and I tried to check for that issue by calling isInputShutdown() but got nothing, that how I am trying:

public String getServerResponse() throws Exception{

      while(true){
                  BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream(), Charset.forName("UTF-8")));
                  if(xbmc_socket.isInputShutdown()){
                     return "stopped";
                  }else{
                     //continue(and that's what it always doing)
                  }
       }
}
Foi útil?

Solução

My problem was because I'm declaring BufferedReader as a local variable (as appears in my code in the question), and that led to an opened socket in the end of the connection either this connection ended from my side or from the other side.

Hence, to overcome this problem, I declared the BufferedReader as a global variable, which enabled me to handle it when connection closed, like closing the socket manually or doing whatever fits my app the best:

public BufferedReader in;
public String getServerResponse() throws Exception{
  while(true){
      in = new BufferedReader(new InputStreamReader(socket.getInputStream(), Charset.forName("UTF-8")));
      // the rest of the code
   }
}  
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top