-1

I have the following code:

while (true) {
    in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    out = new PrintWriter(socket.getOutputStream());

    String result = null;
    while (result != "string") {
        out.println("string one");
        out.flush();

        String var = null;      
        if ((var = in.readLine()) != null) {
            var2 = function(login);
            out.println(var2);
            out.flush();
        }
    }           
}

The flushing is not working correctly, mainly the first iteration of the outer while loop will print both outputs, but then after that there is an odd delay and everything is messed up ("string one" is not printing to the output).

What am I doing wrong?

rajuGT
  • 6,224
  • 2
  • 26
  • 44
Alex
  • 325
  • 7
  • 16

1 Answers1

0

You are using != tocompare String references which isn't going to do what you thinks, though it doesn't matter because you never change anyway.

Most likely you have a bug at the other end which is why readLine() blocks waiting for some text.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130