Home » Community » Newbie corner » TcpSocket, Know when distant connection have been closed
Re: TcpSocket receiving ghost data [message #57221 is a reply to message #57216] |
Sat, 12 June 2021 18:48   |
Oblivion
Messages: 1204 Registered: August 2007
|
Senior Contributor |
|
|
One more thing (general recommendation for anyone reading this topic, not directed specifically at you):
You seem to have the assumption -or that's my impression- that GetLine() will always work on JSON formatted text.
If so, this is a false assumption. GetLine() is a convenience method for retrieving strictly formated texts which have line breaks. For this reason:
1) It cannot be effectively used with raw binary data, because it will always eat bytes '\r' (0xd) and '\n' (0xa).
2) Json (or XML) is not requred to have line breaks. That is optional and purely for cosmetics.
In fact line breaks in JSON/XML are not welcomed on networking circles because of the unnecessary overhead they add. (Think about it: A JSON with 1024 lines with linebreaks will add 1024 bytes to the document to be transferred)
3) My suggestion. Send the string length first thant retrieve the text, using TcpSocket::Get(length) method.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sat, 12 June 2021 19:10] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue Apr 29 00:51:09 CEST 2025
Total time taken to generate the page: 0.03561 seconds
|