I don't know how to implement this function properly. What should this function do exactly, and when (typically) should it be called?

What's the correct method of creating a message anyway, should I first create a server side message, then access it to change it's properties, store its body, etc. from the client? Can someone please tell me (like in points or pseudo code or anything like that) how it should be done? I want to be able to create messages of my specific type (custom MTM implementation) programatically.

Thank you,