Results 1 to 7 of 7

Thread: Server Client QDataStream and QByteArray

  1. #1
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question Server Client QDataStream and QByteArray

    Hi there, I have a Sever Client app that do receive and send information.

    I have made a struct with the important thing that are being send thru.

    I have reimplemented the operator>> << for the QDataStream to put and receive transforn(serialized i think) from the struct.

    but now the customer want to reimplement the client i should give away the "protocol" but i have no idea how to do this since i dont know how the serializacion is done. what can i do to achieve this?, i pretty sure that is possible since what we are sending over tcp it just data plus header, how can i know what the client is writing in the port so if he want to make the client c# ,java or whatever else is posible and i dont have to modified so bad the application. Or shall just send a byteArray with separator(need to specified one) and the tried set the value to the structs manually.

    Thanks for the answers

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Server Client QDataStream and QByteArray

    Its very hard to follow on what the problem is.
    Can you distill your problem description to the problem it self?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Server Client QDataStream and QByteArray

    i want to say to the client what my server application should receive so understand what it should do. But i am not providing the client application.


    Right now the client and the server i have done then,so i never care what happen when i do sth like this:

    Qt Code:
    1. static QDataStream& operator<<(QDataStream& stream, structXX& xx)
    2. {
    3. stream << xx.n() <<xx.str()<<xx.ch();
    4. }
    5. static QDataStream& operator>>(QDataStream & stream, structXX& xx)
    6. {
    7. qint32 n;
    8. QString str;
    9. quint8 ch;
    10. stream >> n;
    11. stream >> str;
    12. stream >> ch;
    13. xx.set_n(n);
    14. xx.set_str(str);
    15. xx.set_ch(ch);
    16. }
    17.  
    18. //on the socket class
    19.  
    20. qint32 socket::send(structXX &xx)
    21. {
    22. QByteArray block;
    23. QDataStream stream(&block, QIODevice::WriteOnly);
    24. stream << (qint64) 0;
    25. stream << xx;
    26. stream.device()->seek(0);
    27. stream << (qint64) (block.size() - sizeof(qint64));
    28. m_Socket->write(block);
    29. m_Socket->flush();
    30. block.clear();
    31. return 0;
    32. }
    33. void socket::slotReadyRead()
    34. {
    35. structXX xx;
    36. QDataStream stream(m_Socket);
    37. if (m_lBlockSize == 0)
    38. {
    39. if (m_Socket->bytesAvailable() < (int) sizeof(qint64))
    40. {
    41. return;
    42. }
    43. stream >> m_lBlockSize;
    44. }
    45. if (m_Socket->bytesAvailable() < m_lBlockSize)
    46. {
    47. return;
    48. }
    49. stream >> message;
    50. }
    To copy to clipboard, switch view to plain text mode 

    So now what i want is to give a set of "strings" to the customer so he can implement the client application by hes own.

    thanks for answers

  4. #4
    Join Date
    May 2010
    Posts
    24
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Server Client QDataStream and QByteArray

    The format used by QDataStream is described there http://doc.trolltech.com/datastreamformat.html
    And the default ordering for numbers is big endian.

  5. #5
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Server Client QDataStream and QByteArray

    Ok, thanks, but still i do not see how to say to the customer what he should send thru the tcp even though he is no using QT.

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Server Client QDataStream and QByteArray

    If I understand you correctly, you should provide a document (Like a RFC) for your protocol and give it to anyone who wants to implement a client that is able to talk with your server.

  7. #7
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Server Client QDataStream and QByteArray

    yeah exactly, that is waht i need....

Similar Threads

  1. QDataStream and QByteArray issue
    By sepehr in forum Qt Programming
    Replies: 13
    Last Post: 2nd April 2021, 16:41
  2. QTcpSocket QDataStream QByteArray
    By Grimlock in forum Newbie
    Replies: 1
    Last Post: 14th December 2009, 22:47
  3. Replies: 9
    Last Post: 25th July 2009, 13:27
  4. how QDataStream and QByteArray related
    By dognzhe in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2009, 08:45
  5. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:23

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.