Does NetworkStream.DataAvailable see buffered data?

前端 未结 2 397
耶瑟儿~
耶瑟儿~ 2021-01-13 13:05

Does NetworkStream.DataAvailable know whether the sender\'s send buffer is empty? Or does it simply indicate whether the receiver\'s read buffer has data? My assumption is t

2条回答
  •  耶瑟儿~
    2021-01-13 14:06

    If you are needing to know when the receiver has received all of the data for a particular message then you definitely need to length prefix.

    I typically define a struct similar to this that goes out at the front of any binary messages i send.

    struct Header
    {
      int packetIdentifier;
      int protocolVersion;
      int messageType;
      int payloadSize;
    }
    

    The identifier lets you determine if you have a valid message of your protocol type. The version lets you revision your protocol. The message type is the type of message (ie: CommsOnline). The payload size is the size of the body of the message.

提交回复
热议问题