PDA

View Full Version : sending quint32 variable in socket



sksingh73
23rd June 2010, 18:43
i have made a server-client program. when i tries to send QString variable, i didn't faced any problem. but when i modified it so as to send quint32 variable, its not working. actually nothing is being received at the other end. please help, below is my modified code

QByteArray arr;
//QString msg = msglineEdit->text();
QDataStream out(&arr, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_1);
out << (qint16)sizeof(calc_mac); //calc_mac is quint32
out << calc_mac;
qDebug() << "created bytearray size:" << arr.size();
qDebug() << "msg size:" << (qint16)sizeof(calc_mac) << "(" << calc_mac << ")";
tcpSocket->write(arr);
while(tcpSocket->bytesToWrite() > 0)
{
tcpSocket->waitForBytesWritten();
}
qDebug() << "bytes written";

ChrisW67
24th June 2010, 01:56
Asking the same question in different threads (http://www.qtcentre.org/threads/31882-How-to-send-quint32-variable-in-server-client) is bad ettiquette. Pick one thread or the other and keep the conversation there, I suggest this one.

What have you tried to help debug this? Is anything going into the QByteArray? Is the socket valid and open? Are all the bytes sent according to the sender? Is the sender reporting any error on the socket? What is the receiver and how is trying to interpret what it is receiving? Is the receiver Qt based (QDataStream implies it is)? How do you know it is not receiving anything? Is the receiver reporting any error on the socket? Do you want to send the calc_mac value in binary or text form? Have you tried debugging the receiving end?