adamatic
3rd March 2009, 09:25
Hello.
I have a question about the portability sending data between Windows and Linux or VxWorks.
I have this qt code to send data from a Windows machine.
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
QString string = QString(QLatin1String(this->mensajeEnviar.mensaje)) ;
out.setVersion(QDataStream::Qt_4_0);
out << (quint16)0;
out <<string;
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
if(tcpSocket->isWritable()){
tcpSocket->write(block);
}
And the datas are arriving well when I use a qt program as receiver, but when i use the following c++ code to read in another machine the datas are not the expected.
// This is a wxworks command and in datagrama_rx char* type receives the sending datas.
if (recvfrom(descriptor, datagrama_rx, SIZE_DATAGRAMA, 0, (sockaddr *)&direccion_origen, &addr_len) !=ERROR)
mensajeRecibido.mensaje=datagrama_rx;
The problem is that datagrama_rx receives what I was written in block, i think the block.data() but when i do the assignation in mensajeRecibido.mensaje which is a char* too it is not well than and with qt code in windows it was working well.
I dont know if i am forgetting something important. Could somone help me?
Thank you in advance.
I have a question about the portability sending data between Windows and Linux or VxWorks.
I have this qt code to send data from a Windows machine.
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
QString string = QString(QLatin1String(this->mensajeEnviar.mensaje)) ;
out.setVersion(QDataStream::Qt_4_0);
out << (quint16)0;
out <<string;
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
if(tcpSocket->isWritable()){
tcpSocket->write(block);
}
And the datas are arriving well when I use a qt program as receiver, but when i use the following c++ code to read in another machine the datas are not the expected.
// This is a wxworks command and in datagrama_rx char* type receives the sending datas.
if (recvfrom(descriptor, datagrama_rx, SIZE_DATAGRAMA, 0, (sockaddr *)&direccion_origen, &addr_len) !=ERROR)
mensajeRecibido.mensaje=datagrama_rx;
The problem is that datagrama_rx receives what I was written in block, i think the block.data() but when i do the assignation in mensajeRecibido.mensaje which is a char* too it is not well than and with qt code in windows it was working well.
I dont know if i am forgetting something important. Could somone help me?
Thank you in advance.