How to send an object using socket c ++ visual studio [closed]

1

I'm trying to send an object to a server socket. The client and server have the same class I use to store the data. It's all working that way, but I'm having problems on the server side.

This is the class I'm using.

class tMensagem{

    private:
       string destinatario;
       string mensagem;

    public:
       tMensagem();
       ~tMensagem();

       string getMensagem();
       void setMensagem(string mensagemTMP);
       string getDestinatario();
       void setDestinatario(string destinatarioTMP);
    };

But when the string is longer than 15 characters, I get some error reading on the server side.

To receive the data I'm using reinterpret_cast

tMensagem * t2 = reinterpret_cast<tMensagem *>(myMessage);

And my recv ():

recv(ClientSocket, (char *)t2, 1024, 0);
    
asked by anonymous 28.09.2018 / 22:07

0 answers