Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved] QLocalSocket creates 2 connections on 1 connectToServer

[Solved] QLocalSocket creates 2 connections on 1 connectToServer

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 3 Posters 3.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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by
    #1

    Hello

    I have a daemon that acts as Unix Domain Sockets Server and it is in state listening.
    When I connect to this server by
    socket->connectToServer(socket_path, QIODevice::ReadWrite);
    it connects twice. The console output from the server shows that accept is run twice and netstat shows me the listening and 2 connected sockets.

    I am new to socket communication. Is this normal behavior?

    In addition some basics questions:
    The Qt app needs to talk very frequently to the server process on this device. Is it best practice to leave the connection established for the lifetime of these processes (reboot of the device) or is it better to close and reopen for every communication?
    Use a separate thread on client(Qt) / server(c app) for the socket communication?

    Thanks for your support.
    McL

    1 Reply Last reply
    0
    • F Offline
      F Offline
      franku
      wrote on last edited by
      #2

      Some suggestions:

      1. Look for a network sniffer (wireshark, packetyzer) that can show you the network traffic to figure out what is happening on the line.

      2a. If you want to realise much throughput then avoid overhead things like opening/closing sockets.

      2b. I would prefer separate threads. Normally such applications are built using pre-threading or with threads created in time when the connection has been established. It depends on the system you are working on.

      This, Jen, is the internet.

      1 Reply Last reply
      0
      • McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

        Thanks for 2a and 2b.
        To 1.: Unix Domain sockets are used for internal IPC only and don't go out to the network. The principles are the same though.

        I am working on a embedded device with an ARM core. The process acting as server is written in native c and controls the chip specific HW parts like video decoder and stuff.
        The Qt app is used as GUI and for handling of external (serial) operation commands. Of course, there is a lot of communication between these 2 processes.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          franku
          wrote on last edited by
          #4

          I do not know much about unix, but could it be that Unix Domain Sockets indeed use two channels to communicate?

          This, Jen, is the internet.

          1 Reply Last reply
          0
          • McLionM Offline
            McLionM Offline
            McLion
            wrote on last edited by
            #5

            Found the issue:
            I did't notice that I don't have to connect the button click manually to the _clicked function if I use the Slot function from the design window to create and jump to _clicked function and crated a connect in the code as well.
            Removing the connect line in the code resolved the doubled connection.

            Still a lot to learn .. when a connect is needed and when not for instance .. still not really sure about that concept.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              danimo
              wrote on last edited by
              #6

              @McLion I'ts really simple: You can either use connect() explicitly or use the special naming of slots as found in the documentation (e.g. _clicked), in which case Qt will do the connection automatically). This was a request from those who migrated from Delphi and weren't used to explicit connect calls. IMHO it tends to confuse people more than its worth (because there are enough cases where you have to use connect() explicitly), but others see that differently.

              1 Reply Last reply
              0
              • McLionM Offline
                McLionM Offline
                McLion
                wrote on last edited by
                #7

                @danimo
                Thanks a lot for the confirmation of my finding and its explanation.

                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