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

前端 未结 4 575
悲&欢浪女
悲&欢浪女 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:24

    The simple loop is the way to go. Given the very small number of bytes you're exchanging, I guess it will need just one iteration to read everything, but if you want to make it correct, you have to loop.

提交回复
热议问题