Anže
Anže

Reputation: 181

QTcpServer receiving and sending in a different thread

I have a piece of software in QT framework (c++) that's suppose to dispatch processed (local) data to other servers and receive the same (foreign) data processed on other servers and compare it.

Problem occurs when a large amount of local data is processed foreign data is buffered and doesn't go into comparison process until all local data is sent. I need the data to be compared in certain time frame, so this causes a timeout.

An idea was to to use one thread to dispatch local data and another thread to receive and compare foreign data. QTcpServer will probably need a mutex to protect it from simultaneous reading and writing.

Is this possible to do with one connection or would it be better to have one connection for dispatching and one for receiving in QT environment?

I checked the Fortune server example http://doc.qt.io/qt-5/qtnetwork-threadedfortuneserver-example.html but I need to know if it's possible and logical to use different threads for sending and receiving on the same connection.

PS. I'm new to multi-threading so I apologise if I misunderstood some concepts.

Upvotes: 1

Views: 234

Answers (1)

TheDarkKnight
TheDarkKnight

Reputation: 27611

Without seeing any code, it's difficult to definitively answer this question. However, this may set you on the right track...

I wouldn't expect you'd need different threads for sending / receiving data; QTcpSocket is asynchronous.

It sounds like the architecture you're using to process the data may need revising.

foreign data is buffered and doesn't go into comparison process until all local data is sent

That sounds like more of an issue and the area where multi-threading would be beneficial. So, use multi-threading for processing the data, rather than controlling the communication between servers.

As you state you're new to multi-threading, I suggest starting by reading this article and using its examples as a template.

Upvotes: 1

Related Questions