Results 1 to 3 of 3

Thread: Fortune Server example

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Fortune Server example

    hi
    in the fortune server example i need a explanation for the below statement
    Qt Code:
    1. out << (quint16)(block.size() - sizeof(quint16));
    To copy to clipboard, switch view to plain text mode 

    which is inside the void Server::sendFortune() function.

    which can be found at the following url
    http://doc.trolltech.com/4.3/network...erver-cpp.html

    while we need the size of the block to be specified at the first two bytes
    why the size of the block is subtracted with the 2bytes(i.e quint16) .

    bye
    Last edited by jpn; 20th December 2007 at 16:08. Reason: Merged a double post

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Fortune Server example

    Don't double post, please.

    It's well explained in the example:
    Qt Code:
    1. out << (quint16)0;
    2. out << fortunes.at(qrand() % fortunes.size());
    3. out.device()->seek(0);
    4. out << (quint16)(block.size() - sizeof(quint16));
    To copy to clipboard, switch view to plain text mode 
    At the start of our QByteArray, we reserve space for a 16 bit integer that will contain the total size of the data block we are sending. We continue by streaming in a random fortune. Then we seek back to the beginning of the QByteArray, and overwrite the reserved 16 bit integer value with the total size of the array. By doing this, we provide a way for clients to verify how much data they can expect before reading the whole packet.
    In other words, it's the size of the fortune, which is the size of the whole block minus the size of the quint16 in the beginning.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    babu198649 (21st December 2007)

  4. #3
    Join Date
    Feb 2011
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Fortune Server example

    hello,
    when i run the fortune server , it says me to run the fortune client and when i run fortune client alongside, and i enter the port no and click get fortune button, it doenot proceed any further and continues to say now run fortune server example alongside

Similar Threads

  1. How to download any file through ftp server
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2007, 01:23
  2. How to ping a server ?
    By Nyphel in forum Newbie
    Replies: 2
    Last Post: 23rd April 2007, 11:27
  3. cannot connect to X server
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 14:22
  4. How a server can write "Hello" to a browser ?
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 1st December 2006, 14:43
  5. synching client readings to server output
    By OnionRingOfDoom in forum Qt Programming
    Replies: 14
    Last Post: 28th January 2006, 18:15

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.