Defined event mechanism for messages.

* Also renamed netsock module to msgsock.
* Refine comments throughout.