Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
Oblivion is currently offline  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


[Updated on: Sat, 12 June 2021 19:10]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: RichEdit with word wrap?
Next Topic: Calendar
Goto Forum:
  


Current Time: Tue Apr 29 00:51:09 CEST 2025

Total time taken to generate the page: 0.03561 seconds