I'm writing a simple streaming JSON service. It consists of JSON messages, sent intermittently, for a long period of time (weeks or months).
What is the best practise with regard to sending multiple JSON messages over a plain TCP socket?
Some alternatives I have looked at (and their downsides) are:
Is there a good, or at least well-established way of doing this?
my first two options would be:
Do what early TCP protocols do: send one message (a JSON object in your case) and close the connection. The client detects it and reopens to get the next object.
Do what chunked-mode HTTP does: first send the number of bytes in the JSON object, a newline (CRLF in HTTP), and your JSON object. The client just have to count bytes to know when the next byte would be the next objectsize.