The most likely explanation is that the line in sentence not "TEST" , but that it looks like "TEST" when it is displayed. The most likely lines are:
" TEST" or "TEST ""TEST\n"
But it is also possible that you have homoglyph both in the client line and in the server code.
Ok, so I just found out using the .length () clause that the sentence is 1024 characters long ... if I take a substring, in particular the .substring (0.4) sentence.
Oh. Therefore, the problem (possibly) is that you ignore the size of the received packet and include the entire buffer array in the line.
The most correct way to extract a string:
new String(receivePacket.getData(), receivePacket.getOffset(), receivePacket.getLength(), "UTF-8");
... although I think the bias will be zero, given the previous statements.
(But it is also possible that the client sends NUL bytes ... in this case, you will also need to make a difference on the client side.)
source share