rewrite message transmitting protocol

rewrite message transmitting protocol, please review 61c2bc756d9a3f4c20c
and some other small changes