Added heartbeat detector and sender.

Won't compile on OSX, but works in Ubuntu. Also fixed error in message serialization
due to old code.