Unsolved cannot write through opened socket
-
Please take a look at the QTcpServer example. Your code does ... nothing really useful.
-
@Christian-Ehrlicher my code is this
open socket with above code, it returns port number port = // get the port number const QString sPort(Port); auto args = QStringList() << sPort << sPort; if (!QProcess::startDetached(sClientName, args)) { const QString sProgFullPath{ QString::fromLatin1(pDir) + QLatin1String("/bin/") + sClientName }; if (!QProcess::startDetached(sProgFullPath, args)) return false; }
-
This code can not work. Follow the QTcpServer examples.
-
@Christian-Ehrlicher this is working code.
i just tried this
i created socket with above method, and run telnet localhost $port
then i sent message to telnet using this port, and it was sent...
so... is that other app faulty? -
@Christian-Ehrlicher my bad
the other app expects file descriptors, and i'm providing socket port
so, how should i work with that app? -
@user4592357 said in cannot write through opened socket:
so, how should i work with that app?
It's your app - how should we know?
-
@Christian-Ehrlicher i mean it is accepting file descriptors, and i have socket (port).
how should i convert socket to fd?
can i do that? -
@user4592357 said in cannot write through opened socket:
how should i convert socket to fd?
By taking a look at the documentation: https://doc.qt.io/qt-5/qabstractsocket.html#socketDescriptor
-
@Christian-Ehrlicher thanks for the link
so when i create the child app like this, when main app is closed, child app still exists, as it was started detached:
if (!QProcess::startDetached(sClientName, args)) { const QString sProgFullPath{ QString::fromLatin1(pDir) + QLatin1String("/bin/") + sClientName }; if (!QProcess::startDetached(sProgFullPath, args)) return false; }
i tried to convert this to using
start()
instead, but looks it's not equivalent (because now error signal is async?)
what's the correct way to nest such call?QProcess p1; p1.start(sClientName, args); connect(&p1, &QProcess::errorOccurred, [] { const QString sProgFullPath{ QString::fromLatin1(pDir) + QLatin1String("/bin/") + sClientName }; QProcess p2; p2.start(sProgFullPath, args); connect(&p2, &QProcess::errorOccurred, [] { // how do i return false from here? }); }
-
Start both directly instead waiting for the first one.
-
@Christian-Ehrlicher what if both succeed?
-