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. How to send a message from a Tcpserver to all connected clients?

How to send a message from a Tcpserver to all connected clients?

Scheduled Pinned Locked Moved Solved General and Desktop
tcpserver
6 Posts 5 Posters 2.2k 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.
  • Z Offline
    Z Offline
    Z0mbi3
    wrote on 13 Mar 2019, 13:45 last edited by
    #1

    Hello to all. Can someone help me to find a way to send a message on Tcpserver event to all connected clients? I just want to send an string to all clients when a pushbutton on server is clicked.

    A 1 Reply Last reply 13 Mar 2019, 14:39
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 13 Mar 2019, 14:35 last edited by
      #2

      Just remember all open sockets in a vector/map/whatever and iterate over this container when you want to send data.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      7
      • Z Z0mbi3
        13 Mar 2019, 13:45

        Hello to all. Can someone help me to find a way to send a message on Tcpserver event to all connected clients? I just want to send an string to all clients when a pushbutton on server is clicked.

        A Offline
        A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 13 Mar 2019, 14:39 last edited by
        #3

        Hi @Z0mbi3,

        You can get an example of what @Christian-Ehrlicher said here: https://code.qt.io/cgit/qt/qtserialbus.git/tree/src/plugins/canbus/virtualcan/virtualcanbackend.cpp#n144

        Regards

        Qt has to stay free or it will die.

        1 Reply Last reply
        4
        • Z Offline
          Z Offline
          Z0mbi3
          wrote on 13 Mar 2019, 15:18 last edited by
          #4

          Allright, thanks to @Christian-Ehrlicher and @aha_1980 to solved my question.

          1 Reply Last reply
          1
          • K Offline
            K Offline
            Kent-Dorfman
            wrote on 13 Mar 2019, 19:38 last edited by
            #5

            and for what its worth, there is really no such thing as a TCP broadcast since it is session/stream oriented. Implementing such is purely an application level function. As others suggested, your daemon needs to keep track of the client list and insert the broadcast message into each client's stream where/when it makes sense to do so. adhoc insertion of messages needs to be thought out carefully when dealing with application level session protocols. Many protocols can break if they receive unsolicited messages from the server, as it is often a client->server query/command, followed by a server->client response.

            J 1 Reply Last reply 13 Mar 2019, 20:52
            2
            • K Kent-Dorfman
              13 Mar 2019, 19:38

              and for what its worth, there is really no such thing as a TCP broadcast since it is session/stream oriented. Implementing such is purely an application level function. As others suggested, your daemon needs to keep track of the client list and insert the broadcast message into each client's stream where/when it makes sense to do so. adhoc insertion of messages needs to be thought out carefully when dealing with application level session protocols. Many protocols can break if they receive unsolicited messages from the server, as it is often a client->server query/command, followed by a server->client response.

              J Offline
              J Offline
              JonB
              wrote on 13 Mar 2019, 20:52 last edited by JonB
              #6

              @Kent-Dorfman
              In which eventuality you'd like to send a out-of-band message, https://en.wikipedia.org/wiki/Out-of-band_data, or e.g. https://docs.microsoft.com/en-us/windows/desktop/winsock/protocol-independent-out-of-band-data-2. Which I have a feeling Qt doesn't support anyway.

              1 Reply Last reply
              0

              2/6

              13 Mar 2019, 14:35

              topic:navigator.unread, 4
              • Login

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