Rewrote message receive routines

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