1

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.

Anže
  • 181
  • 8
  • `QTcpConnection` can only live in _one_ thread. You _have_ to send/receive in the same thread. That said, you don't need to _process_ data in the same thread as the connection, which is the part that might actually take a while. – Nicolas Holthaus May 05 '16 at 18:15

1 Answers1

1

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.

TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85