Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Tcp sockets question

    General and Desktop
    3
    4
    1681
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      great88 last edited by

      If I have a socket called sock and I want to send two different messages to a client
      like so :
      sock->write(message1);
      sock->write(message2);

      , in my clients slot ready_read() , I will get the messages all in one i.e. the data I read
      will be message1 and message2 concatenated .

      But what I really want is for readyRead() to be called twice so I can handle the messages separately .

      How can I do this or what is the standard procedure ? Maybe only way is for client to receive one message at a time
      and inform the server that it is ready for the next message ?

      1 Reply Last reply Reply Quote 0
      • Q
        qxoz last edited by

        Hi!
        Try like this:
        @sock->write(message1);
        sock->waitForBytesWritten();
        sock->write(message2);@
        But i recommend use some high level protocol fo message separation.

        1 Reply Last reply Reply Quote 0
        • K
          KA51O last edited by

          If both messages are sufficiently small they will be send in one package. The TCP/IP packaging is done internally, so it would be best to define a sort of message interface (using SOAP, XML, ...). This also has the benefit that you can create and parse the messages by using available tools that use your message interface definition file (xml from xsd, soap xml from wsdl, ...)

          1 Reply Last reply Reply Quote 0
          • G
            great88 last edited by

            Thanks for the tips guys . Much appreciated .

            1 Reply Last reply Reply Quote 0
            • First post
              Last post