Java InputStream.read(byte[], int, int) method, how to block until the exact number of bytes has been read

前端 未结 4 520
悲&欢浪女
悲&欢浪女 2021-02-04 11:53

I\'m writing a simple client/server network application that sends and receives fixed size messages through a TCP socket.

So far, I\'ve been using the <

4条回答
  •  温柔的废话
    2021-02-04 12:07

    a simple for one-liner will do the trick

    int toread = 60;
    byte[] buff;
    for(int index=0;index

    but most of the time the only reason less bytes would be read is when the stream ends or the bytes haven't all been flushed on the other side

提交回复
热议问题