C # network communication framework networkcomms kernel parsing one message transmission,
Networkcomms.net from the UK official website of the network communication framework www.networkcomms.net Chinese website www.networkcomms.cn
In a network communication program, a local class or object needs to be transmitted to the other end of the communication. It is in the form of a binary stream during transmission over the network.
The object must be serialized as a binary stream when a message is sent.
The recipient will restore the binary data stream to an object.
We know that there is a message boundary problem when using the Tcp protocol to transmit messages. There are many methods to solve this problem, such:
(1) fixed-size messages
(2) Use Message Size Information
(3) Use message tag
Let's take a look at how the networkComms communication framework solves the message boundary problem, and use a picture to explain:
When the NetworkComms framework serializes a Packet object to binary data
For example, the length of the PacketHeader is stored in the first byte. the receiving end parses the packet header based on the length of the packet header stored in the first byte, and then according to the length of the Data part contained in the packet header, parse the data section.
When serializing binary data streams, you need to use a serializer. networkcomms uses the protobuf.net serializer that is popular on the Internet by default. Of course, you can also use the. net built-in
BinaryFormatter for serialization, or other serializer, as long as you specify the serializer during serialization.