- You are designing an application that will emit a status message to the local network, which you will monitor with administrator tools. What kind of socket object would be a good choice?
QUdpSocket would be best here, since it allows for broadcasting packets, and the status packets do not need the overhead of TCP.
- Your GUI class has a QTcpSocket object called self.socket. You've connected its readyRead signal to the following method, but it's not working. What's happening, and how can you fix it?
def on_ready_read(self):
while self.socket.hasPendingDatagrams():
self.process_data(self.socket.readDatagram())
QTcpSocket does not have a hasPendingDatagrams() or readDatagram() method. TCP sockets work with data streams, not datagrams. This method needs to be rewritten to extract data using a QDataStream object.
- Use QTcpServer...