There doesn't seem to be anything wrong with your code. However, a communication log showing the error and at least several lines of client-server communication before it might really help us to understand what is going on - without it, we can only guess why the server closed the connection.
In any case, something like this should not normally occur. The most likely explanation is that a fatal server-side error caused the session to be closed. For example, the server might have been unable to read the actual content of the message for some reason (such as a database failure), and if it already announced to the client that a certain number of bytes of message data is going to follow, it has no choice but to close the session at this point. A server log should contain more information about this.
From the client's side, there is usually not much you can do. If you are able to retrieve other messages and only a single one is causing the error, you might want to try downloading it later. Alternatively, try copying it into another folder or accessing it through the server's web interface (if it has one) and possibly delete it afterwards to work around the issue.