Converting data into a byte array c #

Solve the sticky problem TCP packets and sub-transmission process

The solution is to add a fixed byte length array of bytes in the header of each transmitted byte array, the length of each record for the complete message.

Is converted to a message length byte [] is used to note bitconverter.getbytes () with an int32;

You can not use methods encoding.utf8.getbytes

The difference is that a reference type converter according encoding.utf8.getbytes bytes after converted to different sized digital bytes occupied by the same, the received data can not determine the true start position of the combined bytes

Use bitconverter.getbytes (); conversion, numbers in the range of a limited size, will be converted into bytes of fixed byte length.

Guess you like

Origin www.cnblogs.com/pz904/p/12066450.html