Results 1 to 2 of 2

Thread: sending quint32 variable in socket

  1. #1
    Join Date
    Jun 2010
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default sending quint32 variable in socket

    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";

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: sending quint32 variable in socket

    Asking the same question in different threads 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?

Similar Threads

  1. QByteArray appending quint32 not working
    By TheNewGuy in forum Newbie
    Replies: 3
    Last Post: 30th March 2010, 23:55
  2. QUdpSocket: sending and receiving on the same socket?
    By mhoover in forum Qt Programming
    Replies: 16
    Last Post: 17th June 2009, 03:28
  3. sending structure through udp socket programming
    By hemrajn in forum Qt Programming
    Replies: 9
    Last Post: 15th May 2009, 23:55
  4. Sending Mail
    By systemz89 in forum Qt Programming
    Replies: 11
    Last Post: 15th June 2008, 16:16
  5. sending int array through socket
    By babu198649 in forum Qt Programming
    Replies: 5
    Last Post: 20th December 2007, 08:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.