Results 1 to 3 of 3

Thread: Qt-- Client Server communication problem

  1. #1
    Join Date
    Jan 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt-- Client Server communication problem

    Hallo,

    I must develop a Client application using (Qt) C++. The server application was developed by somebody. I need to register with the Server application to get data from it. I have problems here. Can anybody please let me know how to proceed.

    In order to register with the server, the client must first send a Hello instruction to it. And the format for Hello is as follows:
    Length Contents Term Description
    4 byte xx xx xx xx PACKET_LENGTH Length of the packet in byte
    2 byte 00 01 HELLO Command Hello
    1 byte 02 VERSION Version of protocol
    1 byte 02 Client Type
    variable xx IDENTIFICATION String to identify program

    For eg., I register with the Server with following command
    00 01 02 02 09 MyProgram
    where 00 01 is for hello
    02 is for version
    02 is for Client type
    08 is for length of my string (MyProgram)

    Question:
    How can I send the above command to Server?? What kind of data type should i use for storing this command?? Please note the data must be sent in Motorola byte order.

    I tried with the following code but the server is not accepting.
    Qt Code:
    1. void ClientDialog::sendRequest()
    2. {
    3.  
    4. QByteArray block;
    5. QDataStream out(&block, QIODevice::WriteOnly);
    6. qint16 hello = 0001; // I think problem is here.
    7. short version = 02;
    8. short clientType = 02;
    9. QString identifier = "MyProgram";
    10. qint8 length = identifier.size();
    11.  
    12. out.setVersion(QDataStream::Qt_4_5);
    13. //QDataStream::BigEndian;
    14. out << quint16(0) << hello << version << clientType << length << identifier;
    15. out.device()->seek(0);
    16. out << quint16(block.size()- sizeof(quint16));
    17. tcpSocket.write(block);
    18. ui->currentStatusLabel->setText(tr("Sending request..."));
    19. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance.
    Last edited by wysota; 7th January 2010 at 22:09. Reason: Missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt-- Client Server communication problem

    QDataStream is of no use to you. You need to use QByteArray and then write the array directly to the socket.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt-- Client Server communication problem

    And swap bits on send and recieve
    -- Tanuki

    per cauda vel vaculus cauda

Similar Threads

  1. Client Server
    By electronicboy in forum General Programming
    Replies: 3
    Last Post: 29th October 2009, 10:10
  2. Replies: 1
    Last Post: 27th March 2009, 13:20
  3. password problem with client and server
    By mate in forum Qt Programming
    Replies: 1
    Last Post: 19th July 2008, 18:20
  4. client-server how?
    By nongentesimus in forum Newbie
    Replies: 6
    Last Post: 28th November 2006, 09:25
  5. client/server without port
    By evgenM in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2006, 12:10

Tags for this Thread

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.