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. Do QLocalSockets need a QLocalServer to work?
Forum Updated to NodeBB v4.3 + New Features

Do QLocalSockets need a QLocalServer to work?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 606 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.
  • D Offline
    D Offline
    DannySW
    wrote on last edited by
    #1

    Hi,

    Sorry if this is a simple question...

    I want to implement local sockets for IPC on embedded Linux. I could use the POSIX API and local domain sockets, but thought it would be easier to use the Qt API.

    From the examples I have seen, it appears you need to use a QLocalServer, a QLocalSocket on the server side, and a QLocalSocket on the client side.

    Is is not possible to have a single socket connect to another socket? Is the server required? It seems unnecessary to have a server if I am only establishing a single connection? I do see that QLocalSocket only has a call to connectToServer(name)...

    Hope that makes sense. If anyone can clear this up or point me in the right direction would be grateful.

    Dan

    JonBJ 1 Reply Last reply
    0
    • D DannySW

      Hi,

      Sorry if this is a simple question...

      I want to implement local sockets for IPC on embedded Linux. I could use the POSIX API and local domain sockets, but thought it would be easier to use the Qt API.

      From the examples I have seen, it appears you need to use a QLocalServer, a QLocalSocket on the server side, and a QLocalSocket on the client side.

      Is is not possible to have a single socket connect to another socket? Is the server required? It seems unnecessary to have a server if I am only establishing a single connection? I do see that QLocalSocket only has a call to connectToServer(name)...

      Hope that makes sense. If anyone can clear this up or point me in the right direction would be grateful.

      Dan

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @DannySW
      QLocalServer is what has the calls to listen for and accept a client connection. If you only had 2 QLocalSockets, how would you connect one to the other? I assume " the POSIX API and local domain sockets" have a concept of one side is the server and the other is the client?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DannySW
        wrote on last edited by
        #3

        Yes you are right, Unix domain sockets use a client server concept. I was hoping it could be used as a peer to peer pattern. But yes, one of the sockets must listen for the other one first.

        Thanks for your help.

        JonBJ 1 Reply Last reply
        0
        • D DannySW

          Yes you are right, Unix domain sockets use a client server concept. I was hoping it could be used as a peer to peer pattern. But yes, one of the sockets must listen for the other one first.

          Thanks for your help.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @DannySW
          I'm not sure that they aren't sill "peer to peer" though. In Unix both sides just use a socket(), they simply call different functions on it for server/client at the connection/disconnection phase. I haven't looked at the Qt sources, but I think they have just separated them into two classes so that you know which side you are using, and you can only call client vs server functionality in the respective one, but otherwise similar.

          The QLocalSocket docs do say:

          On Windows this is a named pipe and on Unix this is a local domain socket.

          UPDATE
          OK, I looked at the docs of what each do. The key is QLocalSocket *QLocalServer::nextPendingConnection()

          Returns the next pending connection as a connected QLocalSocket object.

          So that's the connected socket (after accept()) at the server side, to read/write on like at the client side, a QLocalSocket on both sides. QServerSocket encapsulates just the connections part of what you do with the listening socket in Unix.

          1 Reply Last reply
          1

          • Login

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