Avoid busy loop when receiving incoming stream data.

Checking whether bytes are available is a non-blocking operation,
causing the receive loop to become a busy loop.
Ensure errors in json parsing doesn't leave everything in a broken state
Merge pull request #13 from EnJens/master

Avoid busy loop when receiving incoming stream data.