Java TCP How do you read a sent stream size (header) and keep reading based upon that size

前端 未结 3 613
悲哀的现实
悲哀的现实 2021-01-29 11:07

Given the following pseudo code. how would I do read in the given data

\"enter

3条回答
  •  忘掉有多难
    2021-01-29 12:05

    Socket has a getInputStream() method. You would use the returned InputStream and read myShortStreamSize of bytes from it into a byte[], convert that into a int/long representing your payload size and then read into another, larger, new byte[payloadSize], the payload itself.

提交回复
热议问题