What is the minimum number of bytes that will cause Socket.Receive to return?

后端 未结 2 1373
故里飘歌
故里飘歌 2020-12-19 23:52

We are using a application protocol which specifies the length indicator of the message in the first 4 bytes. Socket.Receive will return as much data as in the protocol stac

2条回答
  •  悲&欢浪女
    2020-12-20 00:24

    No, there isn't a minimum buffer size, the length in the receive just needs to match the actual space.

    If you send a length in four bytes before the messages actual data, the recipient needs to handle the cases where 1, 2, 3 or 4 bytes are returned and keep repeating the read until all four bytes are received and then repeat the procedure to receive the actual data.

提交回复
热议问题