31. Nio (selector (message boundary problem (that is, half-package sticky package problem)))

Nio (selector (message boundary problem (that is, half-package sticky package problem)))

Step 1: We set the size of the read event Bytebuffer (we read this data into a buffer (print the contents of the buffer later)) very small. And print out the contents of the buffer through a string

Charset.defaultCharset().decode(buffer)

 

Step 2: The client sends information (the contents of the buffer are ok if it is smaller than the buffer, and it will be garbled if it exceeds)

 

 

Step 3: The client sends data exceeding the buffer size. (Message boundary) Here, because our Chinese characters are Utf-8, it will be parsed into three bytes (here is 6 bytes). The first time our server reads 4 bytes, and then 2 bytes. (country was split)

 

Guess you like

Origin blog.csdn.net/logtcm4/article/details/127820997