The first one implements the protocol imagined for the KnockKnock example: a client sends "KnockKnock", and the server answers.
The second one doesn't make much sense. If the client has a an output stream open with the server, and the server calls readLine()
, it means that it's waiting for a line to come from the client. And the call will block until the client sends a line, or closes the socket.
It seems you don't expect any input from the client. In this case, well, don't open an input stream at all, and don't call readLine()
on the input stream (obviously). Send what you need to send to the client directly, as soon as you want to send it.