ByteArrayOutputStream baos = new ByteArrayOutputStream();
WireFormat wireFormat = new SerializedMuleMessageWireFormat();
wireFormat.setMuleContext(muleContext);
wireFormat.write(baos, msg, msg.getEncoding());
TcpProtocol delegate = createMuleMessageProtocol();
delegate.write(outToServer, baos.toByteArray());
clientSocket.close();
}