Rewrote message receive routines

Rewrote message receive routines to handle incomplete header packets whe...n communicating with devices running iOS 8.
Added type safety and checking of socket/SSL errors.