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?
Forum Update on Monday, May 27th 2025

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 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.

    aha_1980A 1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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

        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.

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 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 last edited by
          #4

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

          1 Reply Last reply
          1
          • Kent-DorfmanK Offline
            Kent-DorfmanK Offline
            Kent-Dorfman
            wrote on 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.

            JonBJ 1 Reply Last reply
            2
            • Kent-DorfmanK Kent-Dorfman

              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.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 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

              • Login

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