Hello Henry,

It sounds to me like you have two separate threads with separate event loops, 
one client thread that sends positions and one GUI thread?

Without having verified this, I would suspect that the operating system would 
prevent a simultaneous read and write to an I/O device. In this case, I think 
the OS would return an error on the write attempt and propagate it to Qt and to 
your application. However, I could be mistaken here, as both accessing threads 
belong to the same process and therefore share resources. If you find that this 
is indeed the case and Qt does not provide its own conflict arbitration, you 
could help yourself with a lock to the socket.

This said, your question is not about PySide specifically, so I would advise to 
resend it to the qt-interest mailing list, the mailing list for developers who 
use Qt: https://lists.qt-project.org/listinfo/interest

Best regards,
Adrian

________________________________________
Von: PySide <pyside-boun...@qt-project.org> im Auftrag von henry.wede--- via 
PySide <pyside@qt-project.org>
Gesendet: Montag, 8. Januar 2024 19:48
An: pyside@qt-project.org
Betreff: [PySide] Advice for QTcpSocket

Hello,

So far, my life with sockets has been very easy.  Now I have something more 
complicated and hope that somebody can provide some guidance.

There are thousands of positions that need to be sent to a robot controller via 
TCP.  The controller can buffer eight positions, so the program has to keep the 
buffer full.  The program can send the positions without a reply and the reply 
will only show up when the robot has moved to that position.  I need to add 
that each position has a unique sequential number.  This means that the "send" 
and "receive" transactions are not coupled together.  I hope that makes sense.

My plan is to start a thread to act as a client.  Then send positions in 
messages.  When the thread gets a readyRead signal it would read all of the 
data (a reply to one of the positions) and then send a signal back to the GUI.  
I will have to come up with some logic to make sure there is always eight 
positions sent to the robot and manage errors.

My question:
The thread would have some sort of self._socket object and a onReadReady method 
to read the data.  What happens if the GUI tries to send a message using 
MyThread_socket.send(MyMessage) while some data is being read?  Does the socket 
nicely wait until the data is read and then send the message or is there some 
sort of collision that breaks everything?  It is pretty likely that the GUI 
will want to send a position while the socket is reading a message

Trying to understand how to handle this "separated" send and receive concept.

Thanks for your suggestions - I hope my explanation was good enough.

Henry


_______________________________________________
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside

Reply via email to