Results 1 to 20 of 43

Thread: cannot read correct len from socket

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: cannot read correct len from socket

    Ok, according to the example you gave, your length seems to have a 2 octet size, if the size is fixed try this

    Qt Code:
    1. QByteArray lenBA(2,'0');
    2.  
    3. client.read(lenBA.data(), 2); // read the first integer for the length
    4. short int length = lenBA.toShort(); // check the conversion is ok here
    5. data.reserve(length);
    6.  
    7. client.read(data.data(), length );
    To copy to clipboard, switch view to plain text mode 

    1632843572 = 0x61533734 and give in ascii : "aS74" look realy close to "47Sa" if you considering byte order issue from brutal conversion from char * to int.
    Last edited by nix; 24th July 2013 at 13:13.

Similar Threads

  1. Replies: 6
    Last Post: 7th October 2012, 16:42
  2. Can't read from socket
    By marekdor in forum Newbie
    Replies: 6
    Last Post: 9th August 2012, 11:06
  3. Read all_ tcp socket
    By Mayssa in forum General Programming
    Replies: 1
    Last Post: 21st February 2012, 17:12
  4. Replies: 2
    Last Post: 22nd May 2011, 21:31
  5. socket read/write bytes
    By nowire75 in forum Newbie
    Replies: 3
    Last Post: 4th July 2007, 23:12

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
  •  
Qt is a trademark of The Qt Company.