To be able to use readLine(), the sending code must send a line break. Only the third attempt (with out.println) does that. But you shouldn't use
println; the line break symbol on the client and server may be different. Instead, use an explicit
\n or
\r\n. Although with readLine() it doesn't really matter as it can handle both.
Another thing: readLine() consumes the line it reads. You'll need to store that in a variable. Modifying your little code snippet you get this:
Another way of doing this is one you will see often in reading code - the read-assign-compare way:
And can you please
UseCodeTags in the future? That'll make your code look a lot better. Just take a look at my code snippets.