2011-12-01, 09:51
el_Paraguayo Wrote:Montellesse,
I'm writing a python script that's trying to catch the "OnStop" notification (by listening on port 9090).
While I can search the data for "OnStop", a neater way would be to detect the end of the notification and then parse the full JSON response.
However, I'm having difficulty in making the script determine the end of the notification as there doesn't seem to be any break character (maybe this is intentional - i.e. as required by the specification).
Do you have any tips for catching the end of the notification?
Thanks,
el_P
You have to count the { and } that you receive from the socket on port 9090. Whenever the number of } matches the number of { you have a whole JSON-RPC notification/response. But ideally you would use some kind of stream-parser because { and } could also appear within strings but this is not the case with any JSON-data generated by XBMC.
This problem has been discussed before and other people have requested to add something like a line break (\n) to the end of every notification/response but that's no good solution at all because it makes scripts depend on something that is not part of the specification. The JSON-RPC specification doesn't state anything apart from saying that all data between notifications/responses must be ignored.