Reputation: 4424
I'm trying to construct two components that communicate via UDP sockets. Component 1 is in the main thread and Component 2 is in a secondary thread. Multiple copies of this application can be running on the same machine at the same time, so I can't used fixed ports. The program also needs to be run on both Windows and Linux.
I've been trying to do this by binding 2 QUdpSockets specifying the port as 0 (asking Qt to choose a free port for me). I then pass the first QUdpSocket and the second socket's parameters to component 1, giving it all it needs to send and receive. For Component 2, I don't think I can pass the QUdpSocket across the thread boundary, so I pass only parameters and construct + bind the socket in the secondary thread.
However, the binding of the socket in the secondary thread fails. Presumably because there's already the socket in the main thread bound to the same port.
Is there any way I can resolve this while still knowing both ports prior to constructing either object?
Upvotes: 1
Views: 1005
Reputation: 229088
I don't think I can pass the QUdpSocket across the thread boundary
You can, so do that. Just don't use it in both your threads simultaneously .
Upvotes: 1