Solved Two processes communicating...
-
One issue in your code is that you have early return statements without any debug information so in the end you might just return early for some reason and that's why you do not see anything happening.
-
@Kent-Dorfman , I had both processes originally working and communicating with each other, then after advice on this forum I re-worked the classes and instead of deriving my classes from QThread I used moveToThread, which introduced a lot of problems which I have now overcome some of the issues, but I still cannot receive the sent message on the host IP and port.
-
@SGaist , I've been using Qt Creator in debug mode and have put breakpoints liberally throughout the code, it is not getting into the onDataIn slot.
-
@SPlatten said in Two processes communicating...:
but I still cannot receive the sent message on the host IP and port.
and what does wireshark tell you? Are you sure the message is being sent? Do you know whether problem is sender or receiver?
-
@Kent-Dorfman , I've installed Wireshark and run capture, I don't see the messages that are being sent. I can see in the Application Output:
D00000000000000000009S000000000003:clsMsgSender::run(): mdFileIO, QAbstractSocket::ConnectedState D00000000000000000010S000000000003:onWrite, to: 192.168.1.158:8123, written: 62, data: {"module":"mdFileIO","msgID":"1","msgType":"init","port":8124} D00000000000000000011S000000000003:onWrite, to: 192.168.1.158:8123, written: 51, data: {"module":"mdFileIO","msgID":"2","msgType":"ready"} D00000000000000000012S000000001995:onWrite, to: 192.168.1.158:8123, written: 60, data: {"module":"mdFileIO","msgID":"3","msgType":"hb","port":8124} D00000000000000000013S000000003992:onWrite, to: 192.168.1.158:8123, written: 60, data: {"module":"mdFileIO","msgID":"4","msgType":"hb","port":8124}
The code that sends the output:
void clsMsgSender::onWrite(QJsonObject objJSON) { if ( mpsckClient->state() == QAbstractSocket::ConnectedState ) { //Associate this TCP socket with the output data stream QByteArray arybytMsg; arybytMsg = QJsonDocument(objJSON).toJson(QJsonDocument::Compact); //Write message qint64 int64Written = mpsckClient->write(arybytMsg); if ( int64Written > 0 ) { QString strMsg(arybytMsg); qdbg() << QString("onWrite, to: %1:%2, written: %3, data: %4") .arg(mpsckClient->peerAddress().toString()) .arg(mpsckClient->peerPort()) .arg(int64Written).arg(strMsg); } } }
So the bytes written is an indication returned by the write function that it was successful but I'm not seeing anything in the Wireshark captured output:
"No.","Time","Source","Destination","Protocol","Length","Info" "1","0.000000","0.0.0.0","255.255.255.255","DHCP","342","DHCP Inform - Transaction ID 0xf8801b27" "2","0.046229","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "3","0.049298","192.168.0.1","255.255.255.255","DHCP","321","DHCP Discover - Transaction ID 0x7e6" "4","1.046923","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "5","2.049593","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "6","3.048590","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "7","4.049566","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "8","5.050152","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "9","5.053241","192.168.0.1","255.255.255.255","DHCP","321","DHCP Discover - Transaction ID 0x19d0" "10","6.052616","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "11","7.051960","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "12","8.052561","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "13","8.969550","0.0.0.0","255.255.255.255","DHCP","342","DHCP Inform - Transaction ID 0xf8801b27" "14","9.053528","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "15","10.055774","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "16","10.058871","192.168.0.1","255.255.255.255","DHCP","321","DHCP Discover - Transaction ID 0x83c" "17","11.054927","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "18","12.055906","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols" "19","13.056473","Tp-LinkT_b7:17:bf","Broadcast","0x8899","60","Realtek Layer 2 Protocols"
-
There are multiple problems, like opening multiple servers for no apparent reason. But what I don't understand is, where's the thread and what is threaded. It's unclear how you create and use the server part ...
-
@kshegunov , there is one process that it’s the server, it spawns other processes that communicate with the server using sockets.
It’s not really client / server, the process that launches the other processes can send notifications to the other processes, the other processes can sent multiple responses in response to a single notification.
-
Please explain what these processes are.
Seems you are writing quite a complexe client server over TCP/IP system for, in the end, stuff that is running within a single machine.
-
@SGaist , I am developing a system where each process will provide expandable functionality, the interface between the main application process and the modules will be a defined JSON system. So far I have written a module that provide's file I/O functions.
I will announce a much more detail when I have it closer to completion and publish all the information.
-
Some things you need to clarify anyway:
-
What do you mean by process ? Actual separate executables that you will start using for example QProcess ? Or separate threads that will do long term operations ?
-
What is the amount of data you expect to move around between your "central application" and your "processes" ?
We won't be able to provide useful answers if you do not share details about your current architecture. As I wrote before you seem to be implemented something very complicated which might in the end be a cannon to shoot a fly.
-
-
@SGaist , when I say a process I mean a completely separate application, not a thread in the same process.
The amount of data at the moment is not identified, but if it’s large I will split it into a multi-part message.
I am implementing something that I hope will revolutionise application development. I’ve been coding professionally since 1987 on various platforms in various languages. I’ve only been using Qt since 2016.
What I’m currently seeing is the call seems to be successful as it returns the correct number of bytes written, but using wireshark I can see no packet on the network matching the written data.
-
@SGaist, fixed, I searched online and found the solution, modified my function adding flush after successful write:
void clsMsgSender::onWrite(QJsonObject objJSON) { if ( mpsckClient->state() == QAbstractSocket::ConnectedState ) { //Associate this TCP socket with the output data stream QByteArray arybytMsg; arybytMsg = QJsonDocument(objJSON).toJson(QJsonDocument::Compact); //Write message qint64 int64Written = mpsckClient->write(arybytMsg); if ( int64Written > 0 ) { QString strMsg(arybytMsg); qdbg() << QString("onWrite, to: %1:%2, written: %3, data: %4") .arg(mpsckClient->peerAddress().toString()) .arg(mpsckClient->peerPort()) .arg(int64Written).arg(strMsg); mpsckClient->flush(); } } }