[Qgis-developer] Socket server freezes on Python plugin
bernhard.stroebl at jena.de
Tue Jun 19 02:34:57 PDT 2012
I happen to have done just that recently. I used QTcpServer, not sure if
it is the best way to do it, but it works with QGIS 1.7.4 and 1.8. I
think I used the PyQt examples. I hope it is of use.
from PyQt4 import QtCore, QtGui, QtSql, QtNetwork
def __init__(self, iface):
app = QgsApplication.instance()
'''create the server'''
self.tcpServer = QtNetwork.QTcpServer()
self.tcpSocket = None # initialize
if not self.tcpServer.listen(port=16500):
QtGui.QMessageBox.critical(None, "Tcp Server",
"Could not start the server: %s." \
'''slot to be called when a client connects to the server'''
self.tcpSocket = self.tcpServer.nextPendingConnection()
'''Slot to read the data sent to the server'''
numbBytes = self.tcpSocket.bytesAvailable()
data = self.tcpSocket.read(numbBytes)
# do something witht the data
Am 19.06.2012 11:18, schrieb Víctor González:
> I'm trying to create a plugin that opens a socket server in a separate
> thread and handles requests. I create the server using
> SocketServer.TCPServer and threading.Thread in the initGui method and
> the plugin starts correctly, but if I try to get a response from a
> client, the server freezes and does not respond.
> The strange thing is that I have added a toolbar button that opens and
> closes a file and, if I click that button, the server unfreezes and I
> get the response as expected. However, if I create the socket server
> with the same exact code as an standalone program, it works as expected
> without freezing.
> I have looked into the PyQgis cookbook  and the contributed plugins
>  searching for an example or solution but I couldn't find anything.
> Does anyone know what may be wrong? Any hint will be greatly
> appreciated. I attach the Qgis plugin as well as the standalone server
> and client.
> Thanks in advance,
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
More information about the Qgis-developer