I am making a streaming API which handles both RPC style calls as well as notifications from the server to the client (not the notifications in the JSON-RPC spec which are client to server). This last part unfortunately rules out JSON-RPC + persistent HTTP.
The API is based on the JSON and JSON-RPC specs.
JSON - http://www.ietf.org/rfc/rfc4627.txt
JSON-RPC - http://www.jsonrpc.org/specification
Typical session might be:
-> Sending to server
<- Receiving from server
-> {'id': 0, 'method':'login','params':{'token':'secret'}}
<- {'id': 0, 'method':'login','result':0}
-> {'id': 1, 'method':'subscribe','params':{'symbol':'VOD.L'}}
<- {'id': 1, 'method':'subscribe','result':0}
...
<- {'method':'notifyPrice','params':{'symbol':'VOD.L', 'bid':10.1, 'ask':10.03}}
<- {'method':'notifyPrice','params':{'symbol':'VOD.L', 'bid':10.2, 'ask':10.03}}
The above messages, particularly the notifications, could come in any order and in the same packet. Neither of the specs seem to include details of a message separator which makes it difficult to know when an entire JSON message has been received without using a SAX based JSON parser, which are rather rare compared to their DOM counterparts.
Am I missing something obvious, or is there genuinely no standard way to separate between multiple JSON messages coming in over the wire?