Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Tcp sockets question
QtWS25 Last Chance

Tcp sockets question

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.9k Views
  • 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 Offline
    G Offline
    great88
    wrote on last edited by
    #1

    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
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      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
      0
      • K Offline
        K Offline
        KA51O
        wrote on last edited by
        #3

        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
        0
        • G Offline
          G Offline
          great88
          wrote on last edited by
          #4

          Thanks for the tips guys . Much appreciated .

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved