Results 1 to 4 of 4

Thread: socket read/write bytes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default socket read/write bytes

    Hi at all!,

    I want to write (an after read) an bytes array to the TCP socket.
    I try with this code:

    Qt Code:
    1. QByteArray block;
    2. QDataStream out(&block, QIODevice::WriteOnly);
    3. out.setVersion(QDataStream::Qt_4_1);
    4.  
    5. QString variable="CIAO";
    6.  
    7. out << quint16(0) << variable;
    8.  
    9. out.device()->seek(0);
    10. out << quint16(block.size() - sizeof(quint16));
    11. tcpSocket.write(block);
    To copy to clipboard, switch view to plain text mode 

    this code work, but the problem is that I not read only "CIAO" on my receiver program.
    I'm waiting to receive 6 bytes... "04CIAO"
    I must change the variable type?

    nowire
    Last edited by nowire75; 3rd July 2007 at 21:49.

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.