I am writing an MTProto client, however when I send a message my connection is closed. Under what conditions might MTProto close my connection?
MTProto servers will close your connection (under TCP at least) if they can't understand what you've sent it; messages sent that have some incorrect parameter will typically receive a reply indicating parameters were incorrect but messages whose composition is fundamentally wrong, e.g: sending the transport code with each message instead of just the first will lead to the connection being closed. Check the code that handles the transport layer for correctness against https://core.telegram.org/mtproto/transports#tcp