1

I am creating an (linux) app and would like to use named socket. I believe that QLocalSocket implemts this. I'm missing something very basic - which is making it hard to understand the docs:

  1. Is QLocalSocket (local domain socket in Linux) full duplex? So would my app read and write to the same socket to talk to another app?

  2. If multiple clients want to talk to my app, can they safely all open the same socket/file? If so, how does my app (or other apps) distinguish which app said what? Are all transmits interleaved?

TSG
  • 4,242
  • 9
  • 61
  • 121

1 Answers1

0

The element it seems you are missing is the QLocalServer class.

First your application creates an instance of QLocalServer and starts it by running the listen() method. This creates a named pipe (\.\pipe[name]) on Windows or a local domain socket file (usually /tmp/[name]) on Linux. Then your other applications can use QLocalSocket to connect to the server application using connectToServer() and communicate as needed.

  • Let's say 2 other apps connect to this QLocalSocket. How does my server app distinguish what info cam from what app? Does QLocalSocket start a thread for each connection? – TSG Mar 10 '14 at 13:02
  • QLocalServer and QLocalSocket can be thought of in the same way as QTcpServer and QTcpSocket respectively. If you want your "server" app to know which "client" app has connected/is sending data to it then you will need some form of description message from the client to the server when the client makes a connection. You can thread the incomingConnection on the server (I recommend looking at the Qt docs for the fortune cookie example) – DragonEmbers Mar 10 '14 at 13:46
  • I see my socket file now (in /tmp/myserver) - how can I test it? I see socat program for linux but having trouble with parameters – TSG Mar 13 '14 at 22:56