Related to : PyQt 4.6.1
This is regarding a simple socket reading in my application.
I am using QAbstractSocket.UdpSocket for the purpose.
Once the socket is connected to given host and port, it should constantly watch for data.
Question 1:
Do I have to use a thread to watch socket for data being available or signal "readyRead" will
do this job?
Question 2:
Code for sending data on socket:
socket.connectToHost(host, port)
socket.writeData("This is the test string.")
socket.disconnectFromHost()
socket.close()
socket = QtNetwork.QAbstractSocket(QtNetwork.QAbstractSocket.UdpSocket, self)
socket.connectToHost(host, port)
socket.writeData("This is the test string.")
socket.disconnectFromHost()
socket.close()
To copy to clipboard, switch view to plain text mode
The line:
socket.writeData("This is the test string.")
socket.writeData("This is the test string.")
To copy to clipboard, switch view to plain text mode
is crashing the application. why?
Question 3:
What's the proper way to close a socket?
I am using:
self.socket.disconnectFromHost()
self.socket.waitForDisconnected()
self.socket.close()
self.socket.disconnectFromHost()
self.socket.waitForDisconnected()
self.socket.close()
To copy to clipboard, switch view to plain text mode
When I am closing the socket using above code, no error or warning is produced, but when I close the dialog box where I am implementing my tests, message is printed to stdout:
QWaitCondition: Destroyed while threads are still waiting
To copy to clipboard, switch view to plain text mode
Please be patient, I have a limited knowledge on threads and sockets.
Bookmarks