Sockets, BufferedReader.readline() - why the stream is not ready?

后端 未结 2 824
-上瘾入骨i
-上瘾入骨i 2021-01-21 15:11

i\'m learning java and i faced some problems with sockets. I developed a simple client-server app - kind of knock-knock, it performs 4 steps:

  1. client sends some mes
2条回答
  •  佛祖请我去吃肉
    2021-01-21 15:43

    You are using public PrintWriter(OutputStream out, boolean autoFlush) which will flush automatically on new line or println. It does not autoflush after every write. You have to flush after every write.

    Here is javadoc for the autoFlush param of the constructor: A boolean; if true, the println, printf, or format methods will flush the output buffer

提交回复
热议问题