PDA

View Full Version : How to use matching settings for synchronous and asynchronous pipes



cyki
25th October 2016, 17:37
Hello everyone,

I have written client application with Qt using QLocalSocket class. As I know Qt opens asynchronous I/O pipes. What if a server was not written in Qt (so it opened synchronous I/O pipe)? Is it possible to tell my client to connect to synchronous I/O pipe? How to use matching settings in such situations? I can change only client side - I do not have access to the server code which is syslog_ng application. When client tries to connect I obtain error: ConnectionRefusedError.

cyki
26th October 2016, 09:00
I am using Linux OS. I have written server application with Qt using QLocalServer class and my client communicates with this server correctly. The problem occures when pipe is open by application that was not written in Qt, e.g. I create named pipe by means of linux command:
$ mkfifo /tmp/test
Then I write some text into this pipe:
$ echo "this is my text" > /tmep/test &
Now I can read this pipe by means of cat application:
$ cat /tmp/test
but when I am trying to read this pipe by means of my client I receive following error: ConnectionRefusedError.
Is it some kind of incompability? Does asynchronous and synchronous I/O pipe concern only Windows or Linux as well?

anda_skoa
26th October 2016, 12:41
I have written client application with Qt using QLocalSocket class. As I know Qt opens asynchronous I/O pipes. What if a server was not written in Qt (so it opened synchronous I/O pipe)?

Not a problem, server and clients are independent.



Is it possible to tell my client to connect to synchronous I/O pipe?

A socket is neither sychronous nor asynchronous, it simply is.
Any participant can open it they way it wants to, without any impact on its peer.


I create named pipe by means of linux command:
$ mkfifo /tmp/test

Probaly a misunderstanding, but this is a pipe, not a Unix domain socket.

Cheers,
_

cyki
26th October 2016, 13:03
Ok, thanks for the answer!

How to create then an application in Qt that will read pipe created by means of mkfifo command?
I used QLocalSocket class in following way:

localSocket = new QLocalSocket(this)
localSocket->connectToServer(/tmep/test, QIODevice::ReadOnly)

but connectToServer() function returns ConnectionRefusedError.

anda_skoa
26th October 2016, 15:22
QLocalSocket uses Unix Domain sockets, not pipes.

You can use system I/O API but very likely also QFile.

Cheers,
_

cyki
26th October 2016, 15:56
OK, now it's clear. Thanks for the help :)