search

Home  >  Q&A  >  body text

java - 输入输出流 为什么两次写操作时间间隔比较短的话 只要一次读操作就能把两次的数据读取出来,要sleep才能分开

高洛峰高洛峰2820 days ago895

reply all(2)I'll reply

  • PHPz

    PHPz2017-04-18 10:37:16

    Only part of the code is pasted, so there is no way to run the test. In addition, your description of the problem scenario is too general. Please organize your language to describe it clearly.

    reply
    0
  • PHPz

    PHPz2017-04-18 10:37:16

    Just looking at this part of the code, I don’t know what you are using for communication.. I assume it is tcp socket

    These APIs, including tcp socket, are all byte stream oriented, and there is no guarantee that one write corresponds to one read.

    If you want one write and one read, that is, "message" oriented, you need to implement it yourself in the upper layer.

    reply
    0
  • Cancelreply