2

After creating socket connection in Android App, i can't write in buffer after reading.

This is an example for establishing connection with my Server:

//...
try{    
    socket = new Socket(IP, Port);
    out = new  PrintWriter(new BufferedWriter(
            new OutputStreamWriter(socket.getOutputStream())), true);
    in =new BufferedReader(new InputStreamReader(socket.getInputStream()));
    //ask for connection
    out.println(req1);
    //server send me a nonce
    result=in.readLine().toString();
    //encrypting nonce with specific alghorithm 
    passwd=Password.get_Passwd(result);
    //sending password 
    out.println(passwd); //here out.println doesn't write 
    //...
} catch (IOException e){
    e.printStackTrace();
} finally {
    try {
        socket.close();
        out.close();
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}   
//...

So can any one help me solving this problem. Thanks.

almightyGOSU
  • 3,731
  • 6
  • 31
  • 41
  • What do you mean by doesn't write?? Did you try adding a breakpoint and debugging??? Did the control reach that line??? Or was it blocked in one of the previous lines itself??? – Codebender Jun 13 '15 at 12:07
  • there is nothing blocked.... only the second println doesn't make anything ... all worked fun just when i read the buffer i can't write in it again only if i recreate my socket, unfortunately in that case new nonce generated and new password needed .... –  Jun 13 '15 at 12:37
  • readLine() can return null. You aren't checking for that, so your code is liable to NPEs. – user207421 Jun 13 '15 at 13:39
  • yes that's it, it return null ... so any other ideas ? –  Jun 15 '15 at 07:54

0 Answers0